MethodComparator implements Comparator<ExecutableElement> { @Override public int compare(ExecutableElement o1, ExecutableElement o2) { int name = o1.getSimpleName().toString().compareTo(o2.getSimpleName().toString()); if (name == 0) { return compareByArgument(o1, o2); } return name; }  @Override int compare(ExecutableElement o1, ExecutableElement o2);  }
@Test public void testCompare() { System.out.println("compare"); String name1 = "a"; String name2 = "b"; ExecutableElement o1 = mock(ExecutableElement.class); ExecutableElement o2 = mock(ExecutableElement.class); Name n1 = mock(Name.class); Name n2 = mock(Name.class); when(o1.getSimpleName()).thenReturn(n1); when(o2.getSimpleName()).thenReturn(n2); when(n1.toString()).thenReturn(name1); when(n2.toString()).thenReturn(name2); doReturn(5).when(instance).compareByArgument(any(ExecutableElement.class), any(ExecutableElement.class)); int result = instance.compare(o1, o2); assertThat(result).isEqualTo(-1); result = instance.compare(o2, o1); assertThat(result).isEqualTo(1); result = instance.compare(o1, o1); assertThat(result).isEqualTo(5); }