### Question:
FailSafeMatcher extends ElementMatcher.Junction.AbstractBase<T> { public boolean matches(T target) { try { return matcher.matches(target); } catch (Exception ignored) { return fallback; } } FailSafeMatcher(ElementMatcher<? super T> matcher, boolean fallback); boolean matches(T target); @Override String toString();  }### Answer:
@Test public void testMatch() throws Exception { when(elementMatcher.matches(target)).thenReturn(true); assertThat(new FailSafeMatcher<Object>(elementMatcher, false).matches(target), is(true)); verifyZeroInteractions(target); verify(elementMatcher).matches(target); verifyNoMoreInteractions(elementMatcher); }
@Test public void testNoMatch() throws Exception { when(elementMatcher.matches(target)).thenReturn(false); assertThat(new FailSafeMatcher<Object>(elementMatcher, false).matches(target), is(false)); verifyZeroInteractions(target); verify(elementMatcher).matches(target); verifyNoMoreInteractions(elementMatcher); }
@Test @SuppressWarnings("unchecked") public void testMatchOnFailure() throws Exception { when(elementMatcher.matches(target)).thenThrow(RuntimeException.class); assertThat(new FailSafeMatcher<Object>(elementMatcher, true).matches(target), is(true)); verifyZeroInteractions(target); verify(elementMatcher).matches(target); verifyNoMoreInteractions(elementMatcher); }
@Test @SuppressWarnings("unchecked") public void testNoMatchOnFailure() throws Exception { when(elementMatcher.matches(target)).thenThrow(RuntimeException.class); assertThat(new FailSafeMatcher<Object>(elementMatcher, false).matches(target), is(false)); verifyZeroInteractions(target); verify(elementMatcher).matches(target); verifyNoMoreInteractions(elementMatcher); }