IsSimilar extends BaseMatcher<CharSequence> { @Override public boolean matches(final Object arg) { checkNotNull(arg); checkArgument(arg instanceof CharSequence, "Expected and instance of CharSequence"); return LevenshteinDistance.distance((CharSequence) arg, target) <= maxDistance; } IsSimilar(final CharSequence target, final int levenshteinDistance); static Matcher<CharSequence> similar(final CharSequence target, final int levenshteinDistance); @Override boolean matches(final Object arg); @Override void describeTo(final Description description);  }
@Test public void testGivenANonCharSequenceWhenMatchesIsCalledThenFalseIsReturned() throws Exception { thrown.expect(IllegalArgumentException.class); new IsSimilar("", -1).matches(new BigDecimal("100")); fail("IllegalArgumentException expected but not thrown"); }