Commits

Przemyslaw Galazka committed a1b48d8

Support for searching mocks candidates in abstract test classes

Comments (0)

Files changed (1)

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) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.