Skip to content

Commit 032b0eb

Browse files
committed
Apply OpenRewrite best practices to FindUnitTests
1 parent 1714582 commit 032b0eb

File tree

2 files changed

+30
-43
lines changed

2 files changed

+30
-43
lines changed

src/main/java/org/openrewrite/java/testing/search/FindUnitTestTable.java

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,33 @@
2020
import org.openrewrite.DataTable;
2121
import org.openrewrite.Recipe;
2222

23-
public class FindUnitTestTable extends DataTable<FindUnitTestTable.Row> {
24-
public FindUnitTestTable(Recipe recipe) {
25-
super(recipe,
26-
"Methods in unit tests",
27-
"Method declarations used in unit tests");
28-
}
29-
30-
@Value
31-
public static class Row {
32-
@Column(displayName = "Full method name",
33-
description = "The fully qualified name of the method declaration")
34-
String fullyQualifiedMethodName;
35-
36-
@Column(displayName = "Method name",
37-
description = "The name of the method declaration")
38-
String methodName;
39-
40-
@Column(displayName = "Method invocation",
41-
description = "How the method declaration is used as method invocation in a unit test.")
42-
String methodInvocationExample;
43-
44-
@Column(displayName = "Name of test",
45-
description = "The name of the unit test where the method declaration is used.")
46-
String nameOfTest;
47-
48-
@Column(displayName = "Location of test",
49-
description = "The location of the unit test where the method declaration is used.")
50-
String locationOfTest;
51-
}
52-
}
53-
23+
public class FindUnitTestTable extends DataTable<FindUnitTestTable.Row> {
24+
public FindUnitTestTable(Recipe recipe) {
25+
super(recipe,
26+
"Methods in unit tests",
27+
"Method declarations used in unit tests");
28+
}
29+
30+
@Value
31+
public static class Row {
32+
@Column(displayName = "Full method name",
33+
description = "The fully qualified name of the method declaration")
34+
String fullyQualifiedMethodName;
35+
36+
@Column(displayName = "Method name",
37+
description = "The name of the method declaration")
38+
String methodName;
39+
40+
@Column(displayName = "Method invocation",
41+
description = "How the method declaration is used as method invocation in a unit test.")
42+
String methodInvocationExample;
43+
44+
@Column(displayName = "Name of test",
45+
description = "The name of the unit test where the method declaration is used.")
46+
String nameOfTest;
47+
48+
@Column(displayName = "Location of test",
49+
description = "The location of the unit test where the method declaration is used.")
50+
String locationOfTest;
51+
}
52+
}

src/main/java/org/openrewrite/java/testing/search/FindUnitTests.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,11 @@
3434

3535
public class FindUnitTests extends ScanningRecipe<FindUnitTests.Accumulator> {
3636

37-
38-
private transient Accumulator acc = new Accumulator();
39-
4037
transient FindUnitTestTable unitTestTable = new FindUnitTestTable(this);
4138

4239
public FindUnitTests() {
4340
}
4441

45-
public FindUnitTests(Accumulator acc) {
46-
this.acc = acc;
47-
}
48-
4942
@Override
5043
public String getDisplayName() {
5144
return "Find unit tests";
@@ -59,10 +52,6 @@ public String getDescription() {
5952
public static class Accumulator {
6053
private final Map<String, AccumulatorValue> unitTestsByKey = new HashMap<>();
6154

62-
public Map<String, AccumulatorValue> getUnitTestAndTheirMethods(){
63-
return this.unitTestsByKey;
64-
}
65-
6655
public void addMethodInvocation(String clazz, String testName, String testBody, J.MethodInvocation invocation) {
6756
String key = clazz + "#" + testName;
6857
AccumulatorValue value = unitTestsByKey.get(key);
@@ -88,7 +77,6 @@ public static class AccumulatorValue {
8877

8978
@Override
9079
public Accumulator getInitialValue(ExecutionContext ctx) {
91-
if (acc != null) return acc;
9280
return new Accumulator();
9381
}
9482

0 commit comments

Comments
 (0)