@Test(expected = AssertionError.class) public void testMethodNotExists() throws IOException { File java = getSampleDataJavaSource("SampleInterface.java"); JavaSourceAssert.assertMethodExists(java, "public void notexists()"); }
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); }
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); } }
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); }  }
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); }
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);  }