### Question:
ClassLoaderHierarchyMatcher extends ElementMatcher.Junction.AbstractBase<T> { public boolean matches(T target) { ClassLoader current = target; while (current != null) { if (matcher.matches(current)) { return true; } current = current.getParent(); } return matcher.matches(null); } ClassLoaderHierarchyMatcher(ElementMatcher<? super ClassLoader> matcher); boolean matches(T target); @Override String toString();  }### Answer:
@Test public void testMatchesChild() throws Exception { when(classLoaderMatcher.matches(classLoader)).thenReturn(true); assertThat(new ClassLoaderHierarchyMatcher<ClassLoader>(classLoaderMatcher).matches(classLoader), is(true)); verify(classLoaderMatcher).matches(classLoader); verifyNoMoreInteractions(classLoaderMatcher); }
@Test public void testMatchesParent() throws Exception { when(classLoaderMatcher.matches(null)).thenReturn(true); assertThat(new ClassLoaderHierarchyMatcher<ClassLoader>(classLoaderMatcher).matches(classLoader), is(true)); verify(classLoaderMatcher).matches(classLoader); verify(classLoaderMatcher).matches(null); verifyNoMoreInteractions(classLoaderMatcher); }
@Test public void testNoMatch() throws Exception { assertThat(new ClassLoaderHierarchyMatcher<ClassLoader>(classLoaderMatcher).matches(classLoader), is(false)); verify(classLoaderMatcher).matches(classLoader); verify(classLoaderMatcher).matches(null); verifyNoMoreInteractions(classLoaderMatcher); }