Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 78d2a98

Browse files
committed
Cleanup JUnit Support by removing unused code and got rid of static class
1 parent f025f08 commit 78d2a98

File tree

6 files changed

+11
-34
lines changed

6 files changed

+11
-34
lines changed

webtester-support-junit4/src/main/java/info/novatec/testit/webtester/junit/exceptions/IllegalTestClassStructureException.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
@SuppressWarnings("serial")
44
public class IllegalTestClassStructureException extends WebTesterJUnitSupportException {
55

6-
public IllegalTestClassStructureException(String message, Throwable cause) {
7-
super(message, cause);
8-
}
9-
106
public IllegalTestClassStructureException(String message) {
117
super(message);
128
}

webtester-support-junit4/src/main/java/info/novatec/testit/webtester/junit/exceptions/WebTesterJUnitSupportException.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
@SuppressWarnings("serial")
77
public class WebTesterJUnitSupportException extends WebTesterException {
88

9-
protected WebTesterJUnitSupportException(String message, Throwable cause) {
10-
super(message, cause);
11-
}
12-
139
protected WebTesterJUnitSupportException(String message) {
1410
super(message);
1511
}

webtester-support-junit4/src/main/java/info/novatec/testit/webtester/junit/runner/WebTesterJUnitRunner.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
*/
133133
public class WebTesterJUnitRunner extends BlockJUnit4ClassRunner {
134134

135+
private ReflectionUtils reflectionUtils = new ReflectionUtils();
135136
private List<ClassTestBrowser> classBrowsers = new ArrayList<>();
136137
private List<MethodTestBrowser> methodBrowsers = new ArrayList<>();
137138

@@ -155,7 +156,7 @@ public void evaluate() throws Throwable {
155156
private void initializeClassLevel() {
156157
classBrowsers.clear();
157158
Class<?> testClass = getTestClass().getJavaClass();
158-
for (Field field : ReflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
159+
for (Field field : reflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
159160
boolean fieldIsStatic = Modifier.isStatic(field.getModifiers());
160161
boolean fieldIsABrowser = Browser.class.isAssignableFrom(field.getType());
161162
boolean fieldIsAnnotatedAsResource = field.getAnnotation(Resource.class) != null;
@@ -188,7 +189,7 @@ private void evaluateWithBeforeClassesFromSuperClass() throws Throwable {
188189
private boolean configurationValuesAnnotationIsUsedOnClassLevel() {
189190
boolean isUsed = false;
190191
Class<?> testClass = getTestClass().getJavaClass();
191-
for (Field field : ReflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
192+
for (Field field : reflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
192193
boolean isStatic = Modifier.isStatic(field.getModifiers());
193194
boolean isAnnotated = field.isAnnotationPresent(ConfigurationValue.class);
194195
if (isStatic && isAnnotated) {
@@ -237,7 +238,7 @@ public void evaluate() throws Throwable {
237238
private void initializeMethodLevel() {
238239
methodBrowsers.clear();
239240
Class<?> testClass = getTestClass().getJavaClass();
240-
for (Field field : ReflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
241+
for (Field field : reflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
241242
boolean fieldIsNonStatic = !Modifier.isStatic(field.getModifiers());
242243
boolean fieldIsABrowser = Browser.class.isAssignableFrom(field.getType());
243244
boolean fieldIsAnnotatedAsResource = field.getAnnotation(Resource.class) != null;
@@ -269,7 +270,7 @@ private void evaluateWithBeforesFromSuperClass() throws Throwable {
269270
private boolean configurationValuesAnnotationIsUsedOnMethodLevel() {
270271
boolean isUsed = false;
271272
Class<?> testClass = getTestClass().getJavaClass();
272-
for (Field field : ReflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
273+
for (Field field : reflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
273274
boolean isStatic = Modifier.isStatic(field.getModifiers());
274275
boolean isAnnotated = field.isAnnotationPresent(ConfigurationValue.class);
275276
if (!isStatic && isAnnotated) {

webtester-support-junit4/src/main/java/info/novatec/testit/webtester/junit/runner/internal/TestClassPlausibilityChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class TestClassPlausibilityChecker {
2323
private Set<Field> allFields;
2424

2525
public TestClassPlausibilityChecker(Class<?> testClass) {
26-
this.allFields = ReflectionUtils.getAllFieldsOfClassHierarchy(testClass);
26+
this.allFields = new ReflectionUtils().getAllFieldsOfClassHierarchy(testClass);
2727
}
2828

2929
public void assertPlausibilityOfTestClass() {

webtester-support-junit4/src/main/java/info/novatec/testit/webtester/junit/utils/ReflectionUtils.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22

33
import java.lang.reflect.Field;
44
import java.util.Collections;
5-
import java.util.HashMap;
65
import java.util.HashSet;
7-
import java.util.Map;
86
import java.util.Set;
97

108

11-
public final class ReflectionUtils {
12-
13-
private static final Map<Class<?>, Set<Field>> FIELDS_CACHE = new HashMap<>();
14-
15-
/* getting fields */
9+
public class ReflectionUtils {
1610

1711
/**
1812
* Returns all fields of the given class hierarchy (start class and all its
@@ -23,29 +17,19 @@ public final class ReflectionUtils {
2317
* be returned
2418
* @return all fields of the given class hierarchy
2519
*/
26-
public static Set<Field> getAllFieldsOfClassHierarchy(Class<?> startClass) {
27-
28-
Set<Field> fields = FIELDS_CACHE.get(startClass);
29-
if (fields != null) {
30-
return fields;
31-
}
20+
public Set<Field> getAllFieldsOfClassHierarchy(Class<?> startClass) {
3221

3322
Field[] declaredFields = startClass.getDeclaredFields();
3423

35-
fields = new HashSet<>(declaredFields.length);
24+
Set<Field> fields = new HashSet<>(declaredFields.length);
3625
Collections.addAll(fields, declaredFields);
3726

3827
Class<?> superclass = startClass.getSuperclass();
3928
if (superclass != null) {
4029
fields.addAll(getAllFieldsOfClassHierarchy(superclass));
4130
}
42-
43-
FIELDS_CACHE.put(startClass, fields);
4431
return fields;
4532

4633
}
4734

48-
private ReflectionUtils() {
49-
}
50-
5135
}

webtester-support-junit4/src/test/java/info/novatec/testit/webtester/junit/utils/ReflectionUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class ReflectionUtilsTest {
1212

13-
/* testGetAllFieldsOfClassHierarchy */
13+
ReflectionUtils cut = new ReflectionUtils();
1414

1515
@Test
1616
public final void testGetAllFieldsOfClassHierarchy() throws Exception {
@@ -19,7 +19,7 @@ public final void testGetAllFieldsOfClassHierarchy() throws Exception {
1919
Field fatherField = Father.class.getDeclaredField("fatherField");
2020
Field grandfatherField = Grandfather.class.getDeclaredField("grandfatherField");
2121

22-
Set<Field> fields = ReflectionUtils.getAllFieldsOfClassHierarchy(Child.class);
22+
Set<Field> fields = cut.getAllFieldsOfClassHierarchy(Child.class);
2323

2424
assertThat(fields).contains(childField, fatherField, grandfatherField);
2525

0 commit comments

Comments
 (0)