Commits

Przemyslaw Galazka  committed a1b48d8

Support for searching mocks candidates in abstract test classes

  • Participants
  • Parent commits 74fb810

Comments (0)

Files changed (1)

File springockito-annotations/src/main/java/org/kubek2k/springockito/annotations/internal/SpringockitoDefinitionFinder.java

     private BeanNameResolver beanNameResolver = new BeanNameResolverChainOfResponsibility();
 
     public Set<SpringockitoDefinition> findSpringockitoDefinitions(Class<?> clazz) {
-        Set<SpringockitoDefinition> springockitoDefinitions = new HashSet<SpringockitoDefinition>();
-        for (Field field : clazz.getDeclaredFields()) {
+
+        Set<SpringockitoDefinition> result = new HashSet<SpringockitoDefinition>();
+
+        while (clazz != null) {
+            result.addAll(findDefinitions(clazz));
+            clazz = clazz.getSuperclass();
+        }
+
+        return result;
+    }
+
+    private Set<SpringockitoDefinition> findDefinitions(Class<?> currentClass) {
+
+        Set<SpringockitoDefinition> definitions = new HashSet<SpringockitoDefinition>();
+
+        for (Field field : currentClass.getDeclaredFields()) {
             if (field.isAnnotationPresent(ReplaceWithMock.class)) {
-                springockitoDefinitions.add(newMockDefinition(field));
+                definitions.add(newMockDefinition(field));
             } else if (field.isAnnotationPresent(WrapWithSpy.class)) {
-                springockitoDefinitions.add(newSpyDefinition(field));
+                definitions.add(newSpyDefinition(field));
             }
         }
-        return springockitoDefinitions;
+
+        return definitions;
     }
 
     private SpyDefinition newSpyDefinition(Field field) {