### Question:
Processors implements Elements, Types { public ExecutableElement getMethodByName(TypeElement typeElement, String methodName) { return typeElement.getEnclosedElements().stream() .filter(element -> element.getKind().equals(ElementKind.METHOD)) .filter(method -> method.getSimpleName().contentEquals(methodName)) .map(method -> (ExecutableElement) method) .findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("no such method [%s] in [%s]", methodName, typeElement))); } @Inject  Processors(ProcessorContext processorContext); TypeElement getTypeElement(Class<?> clazz); DeclaredType getDeclaredType(Class<?> type, Class<?>... typeArguments); boolean isSameType(TypeMirror typeMirror, Class<?> type, Class<?>... typeArguments); ExecutableElement getMethodByName(TypeElement typeElement, String methodName); TypeMirror getSupertypeWithErasureSameAs(TypeMirror typeMirror, TypeMirror supertype);  }### Answer:
@Test void getMethodByName_methodExists_returnsExecutableElement() { doReturn(singletonList(executableElementMock)).when(typeElementMock).getEnclosedElements(); when(executableElementMock.getKind()).thenReturn(ElementKind.METHOD); when(executableElementMock.getSimpleName()).thenReturn(nameMock); when(nameMock.contentEquals("methodName")).thenReturn(true); ExecutableElement method = classUnderTest.getMethodByName(typeElementMock, "methodName"); assertThat(method).isEqualTo(executableElementMock); }
@Test void getMethodByName_noMethodByName_throwsIllegalArgumentException() { doReturn(singletonList(executableElementMock)).when(typeElementMock).getEnclosedElements(); when(executableElementMock.getKind()).thenReturn(ElementKind.METHOD); when(executableElementMock.getSimpleName()).thenReturn(nameMock); when(nameMock.contentEquals("methodName")).thenReturn(false); assertThatThrownBy(() -> classUnderTest.getMethodByName(typeElementMock, "methodName")) .isInstanceOf(IllegalArgumentException.class); }
@Test void getMethodByName_noMethods_throwsIllegalArgumentException() { doReturn(singletonList(elementMock)).when(typeElementMock).getEnclosedElements(); when(elementMock.getKind()).thenReturn(ElementKind.FIELD); assertThatThrownBy(() -> classUnderTest.getMethodByName(typeElementMock, "methodName")) .isInstanceOf(IllegalArgumentException.class); }