### Question:
CachingMatcher extends ElementMatcher.Junction.AbstractBase<T> { public boolean matches(T target) { Boolean cached = map.get(target); if (cached == null) { cached = onCacheMiss(target); } return cached; } CachingMatcher(ElementMatcher<? super T> matcher, ConcurrentMap<? super T, Boolean> map); boolean matches(T target); @Override String toString();  }### Answer:
@Test public void testMatchCachesNoEviction() throws Exception { ElementMatcher<Object> matcher = new CachingMatcher<Object>(this.matcher, map); assertThat(matcher.matches(target), is(true)); assertThat(matcher.matches(target), is(true)); verify(this.matcher).matches(target); verifyNoMoreInteractions(this.matcher); verifyZeroInteractions(target); }
@Test public void testMatchCachesEviction() throws Exception { ElementMatcher<Object> matcher = new CachingMatcher.WithInlineEviction<Object>(this.matcher, map, 1); Object other = mock(Object.class); assertThat(matcher.matches(target), is(true)); assertThat(matcher.matches(other), is(false)); assertThat(matcher.matches(other), is(false)); assertThat(matcher.matches(target), is(true)); verify(this.matcher, times(2)).matches(target); verify(this.matcher).matches(other); verifyNoMoreInteractions(this.matcher); verifyZeroInteractions(target); }
@Test public void testMatchNoCachesEviction() throws Exception { ElementMatcher<Object> matcher = new CachingMatcher.WithInlineEviction<Object>(this.matcher, map, 2); Object other = mock(Object.class); assertThat(matcher.matches(target), is(true)); assertThat(matcher.matches(other), is(false)); assertThat(matcher.matches(other), is(false)); assertThat(matcher.matches(target), is(true)); verify(this.matcher).matches(target); verify(this.matcher).matches(other); verifyNoMoreInteractions(this.matcher); verifyZeroInteractions(target); }