hardayal / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

ReflectiveFactoryMatcher misses factories that return subclasses of Matcher #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi all,

I was bit by a bug that caused ReflectiveFactoryMatcher to miss
factory methods that return a subclass of Matcher.  That is, I believe
this test should pass:

   public static class SubclassOfMatcher {
       @Factory
       public static BaseMatcher subclassMethod() {
           return null;
       }
   }

   public void testCatchesSubclasses() {
       Iterable<FactoryMethod> reader = new
ReflectiveFactoryReader(SubclassOfMatcher.class);
       Iterator<FactoryMethod> methods = reader.iterator();
       assertTrue("Expected first method", methods.hasNext());
   }

And I think all it takes to do it is reversing the way that
isAssignableFrom is used in ReflectiveFactoryMatcher:

   protected boolean isFactoryMethod(Method javaMethod) {
       return isStatic(javaMethod.getModifiers())
               && isPublic(javaMethod.getModifiers())
               && javaMethod.getAnnotation(Factory.class) != null
               && Matcher.class.isAssignableFrom(javaMethod.getReturnType());
   }

Original issue reported on code.google.com by david.s...@gmail.com on 22 Dec 2006 at 4:00

GoogleCodeExporter commented 8 years ago
Thanks David. I've applied your fix to trunk.

-Joe

Original comment by joe.wal...@gmail.com on 22 Dec 2006 at 9:11