### Question:
JavaSourceAssert { public static JavaMethod assertMethodExists(File java, CharSequence methodSignature) throws IOException { JavaDocBuilder builder = new JavaDocBuilder(); JavaSource src = builder.addSource(java); JavaClass jc = getClassName(src, java); Map<String, JavaMethod> sigs = new HashMap<String, JavaMethod>(); for (JavaMethod method : jc.getMethods()) { if (!method.isConstructor()) { sigs.put(getCompleteMethodSignature(method), method); } } if (!sigs.containsKey(methodSignature)) { StringBuilder msg = new StringBuilder(); msg.append("Expected method signature not found: "); msg.append(methodSignature); msg.append("\nMethods present in java source:"); for (String sig : sigs.keySet()) { msg.append("\n ").append(sig); } Assert.fail(msg.toString()); } return sigs.get(methodSignature); }  static JavaClass assertIsInterface(File java); static void assertBodyContains(AbstractJavaEntity entity, CharSequence expectedContents); static void assertMethodsEqual(JavaMethod expectedMethod, JavaMethod actualMethod); static void assertMethodsEqual(File expectedJava, File actualJava, String signature); static JavaMethod assertConstructorExists(File java, CharSequence signature); static JavaMethod assertMethodExists(File java, CharSequence methodSignature);  }### Answer:
@Test public void testMethodExists() throws IOException { File java = getSampleDataJavaSource("SampleInterface.java"); JavaMethod method; method = JavaSourceAssert.assertMethodExists(java, "public void example()"); Assert.assertNotNull("Method", method); method = JavaSourceAssert.assertMethodExists(java, "public void execute(boolean flags) throws IOException"); Assert.assertNotNull("Method", method); }
@Test(expected = AssertionError.class) public void testMethodNotExists() throws IOException { File java = getSampleDataJavaSource("SampleInterface.java"); JavaSourceAssert.assertMethodExists(java, "public void notexists()"); }
@Test public void testMethodExistsWithGenerics() throws IOException { File java = getSampleDataJavaSource("SampleObject.java"); JavaMethod method = JavaSourceAssert.assertMethodExists(java, "public static List<Class<?>> getImplementations() throws IOException"); Assert.assertNotNull("Method", method); }