예제 #1
0
 @Test
 public void duplicatesFound() {
   ListSavingMethodCallback mc = new ListSavingMethodCallback();
   ReflectionUtils.doWithMethods(TestObjectSubclass.class, mc);
   int absquatulateCount = 0;
   for (String name : mc.getMethodNames()) {
     if (name.equals("absquatulate")) {
       ++absquatulateCount;
     }
   }
   assertEquals("Found 2 absquatulates", 2, absquatulateCount);
 }
예제 #2
0
 @Test
 public void doWithProtectedMethods() {
   ListSavingMethodCallback mc = new ListSavingMethodCallback();
   ReflectionUtils.doWithMethods(
       TestObject.class,
       mc,
       new ReflectionUtils.MethodFilter() {
         @Override
         public boolean matches(Method m) {
           return Modifier.isProtected(m.getModifiers());
         }
       });
   assertFalse(mc.getMethodNames().isEmpty());
   assertTrue("Must find protected method on Object", mc.getMethodNames().contains("clone"));
   assertTrue("Must find protected method on Object", mc.getMethodNames().contains("finalize"));
   assertFalse("Public, not protected", mc.getMethodNames().contains("hashCode"));
   assertFalse("Public, not protected", mc.getMethodNames().contains("absquatulate"));
 }