### Question:
MethodOverrideMatcher extends ElementMatcher.Junction.AbstractBase<T> { public boolean matches(T target) { Set<TypeDescription> duplicates = new HashSet<TypeDescription>(); for (TypeDefinition typeDefinition : target.getDeclaringType()) { if (matches(target, typeDefinition) || matches(target, typeDefinition.getInterfaces(), duplicates)) { return true; } } return false; } MethodOverrideMatcher(ElementMatcher<? super TypeDescription.Generic> matcher); boolean matches(T target); @Override String toString();  }### Answer:
@Test public void testDirectMatch() throws Exception { when(declaredTypeMethod.asSignatureToken()).thenReturn(token); when(typeMatcher.matches(declaringType)).thenReturn(true); assertThat(new MethodOverrideMatcher<MethodDescription>(typeMatcher).matches(methodDescription), is(true)); verify(typeMatcher).matches(declaringType); verifyNoMoreInteractions(typeMatcher); }
@Test public void testSuperTypeMatch() throws Exception { when(declaredTypeMethod.asSignatureToken()).thenReturn(otherToken); when(interfaceTypeMethod.asSignatureToken()).thenReturn(otherToken); when(superTypeMethod.asSignatureToken()).thenReturn(token); when(typeMatcher.matches(superType)).thenReturn(true); assertThat(new MethodOverrideMatcher<MethodDescription>(typeMatcher).matches(methodDescription), is(true)); verify(typeMatcher).matches(superType); verifyNoMoreInteractions(typeMatcher); }
@Test public void testInterfaceTypeMatch() throws Exception { when(declaredTypeMethod.asSignatureToken()).thenReturn(otherToken); when(superTypeMethod.asSignatureToken()).thenReturn(otherToken); when(interfaceTypeMethod.asSignatureToken()).thenReturn(token); when(typeMatcher.matches(interfaceType)).thenReturn(true); assertThat(new MethodOverrideMatcher<MethodDescription>(typeMatcher).matches(methodDescription), is(true)); verify(typeMatcher).matches(interfaceType); verifyNoMoreInteractions(typeMatcher); }
@Test public void testNoMatchMatcher() throws Exception { when(declaredTypeMethod.asSignatureToken()).thenReturn(token); when(superTypeMethod.asSignatureToken()).thenReturn(token); when(interfaceTypeMethod.asSignatureToken()).thenReturn(token); assertThat(new MethodOverrideMatcher<MethodDescription>(typeMatcher).matches(methodDescription), is(false)); verify(typeMatcher).matches(declaringType); verify(typeMatcher).matches(superType); verify(typeMatcher).matches(interfaceType); verifyNoMoreInteractions(typeMatcher); }
@Test public void testNoMatch() throws Exception { when(declaredTypeMethod.asSignatureToken()).thenReturn(otherToken); when(superTypeMethod.asSignatureToken()).thenReturn(otherToken); when(interfaceTypeMethod.asSignatureToken()).thenReturn(otherToken); assertThat(new MethodOverrideMatcher<MethodDescription>(typeMatcher).matches(methodDescription), is(false)); verifyZeroInteractions(typeMatcher); }