2

I'm looking for some sort of OO equivalent to the apache commons utility, which is the common way of handling this in java:

StringUtils.containsIgnoreCase("foobar", "OOB")

Is there a way to do this in cactoos? I've read through the source code and tests, but don't see anything that relates to it yet.

I can't picture it being used a lot in most development situations, but it's something I use quite frequently with automated testing.

To add some more context: Most of these checks have to do with selecting values on a web page that match a customer's data, but we want to avoid issues with text conversions and formatting in the UI layout.

An assert would technically work, but I'd prefer to avoid using exceptions to handle control flow.

Chs
  • 131
  • 1
  • 6
  • Possible duplicate of [How to check if a String contains another String in a case insensitive manner in Java?](https://stackoverflow.com/questions/86780/how-to-check-if-a-string-contains-another-string-in-a-case-insensitive-manner-in) – Logan Jun 07 '18 at 23:03
  • @Logan I'm specifically looking for a way to handle this with cactoos. I've got an answer to handle this via procedural approach in the description above, but that snippet and the answers in the linked question are all based on static methods, not objects. – Chs Jun 15 '18 at 18:46

2 Answers2

2

We moved all our hamcrest matchers to llorllale/cactoos-matchers.

Starting from org.llorllale:cactoos-matchers:0.11 and org.cactoos:cactoos:0.35 you can do:

MatcherAssert.assertThat(
  new UpperText("foobar"),
  new TextHasString("OOB")
);

We still haven't provided a OO alternative to MatcherAssert.assertThat - that will come later with #18 Assertion has been implemented.

George Aristy
  • 1,373
  • 15
  • 17
  • I'll check out the library, thanks! I'm debating whether or not to try using matchers outside of asserts, like `matchesSafely`, but it seems a bit awkward. Any thoughts? – Chs Jun 15 '18 at 18:51
  • You mean you want to stop using `Matcher.assert*()` methods and instead do if-else logic directly with the matchers? – George Aristy Jun 15 '18 at 19:03
  • A specific use-case would be checking the heading text on a web page to ensure the right page section has loaded before the test proceeds. -- I've run into issues in the past where css changes can make the same text appear in uppercase letters, which would break the test. A case-insensitive comparison would be ideal. I'm just not sure if a cactoos text + matchesSafely combination would be a smelly solution. – Chs Jul 12 '18 at 21:10
0

You may use org.cactoos.text.Contains, more examples here https://github.com/yegor256/cactoos/blob/master/src/test/java/org/cactoos/text/ContainsTest.java

    @Test
    public void stringContainsText() {
        new Assertion<>(
            "String contains other Text",
            new Contains(
                "Terra incognita",
                new TextOf("cognita")
            ),
            new ScalarHasValue<>(Boolean.TRUE)
        ).affirm();
    }
lazylead
  • 1,453
  • 1
  • 14
  • 26