AbstractSimpleStringMatcher extends AbstractSimpleMatcher { @Override protected final boolean matches(Parameter parameter, Object actual, Object expected) { if (!(actual instanceof String) || !(expected instanceof String)) { throw new InvalidArgumentException("Expected string values for property: " + parameter.getPath()); } String first = (String) actual; String second = (String) expected; if (parameter.getModifiers().contains(Modifier.IGNORE_CASE)) { first = first.toLowerCase(); second = second.toLowerCase(); } return matches(first, second); }    }
@Test(expectedExceptions = InvalidArgumentException.class, expectedExceptionsMessageRegExp = ".*x.y.z.*") public void testValueNotAString() { final NotMatchingStringMatcher matcher = new NotMatchingStringMatcher(); matcher.matches(new ImmutableParameter("x.y.z", null, null, null), 1, ""); }
@Test(expectedExceptions = InvalidArgumentException.class, expectedExceptionsMessageRegExp = ".*x.y.z.*") public void testParameterNotAString() { final NotMatchingStringMatcher matcher = new NotMatchingStringMatcher(); matcher.matches(new ImmutableParameter("x.y.z", null, null, null), "", 1); }
@Test public void testWhenBothAreStrings() { final NotMatchingStringMatcher matcher = new NotMatchingStringMatcher(); matcher.matches(new ImmutableParameter("x.y.z", null, null, null), "", ""); }
@Test public void testWhenIgnoringCase() { final NotMatchingStringMatcher matcher = new NotMatchingStringMatcher(); matcher.matches(new ImmutableParameter("x.y.z", Collections.singleton(Modifier.IGNORE_CASE), null, null), "test", "TEST"); assertThat(matcher.getActual(), is("test")); assertThat(matcher.getArgument(), is("test")); }