Skip to content

Commit b4a8eaf

Browse files
Migrate tests to JUnit5 (archetype)
* Migrate annotations and imports * Migrate assertions * Remove public visibility for test classes and methods * Minor code cleanup
1 parent 07f8061 commit b4a8eaf

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

archetype/src/main/resources/archetype-resources/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<groupId>\${groupId}</groupId>
55
<artifactId>\${artifactId}</artifactId>
66
<version>\${version}</version>
7-
7+
88
<name>\${artifactId}</name>
99
<packaging>jar</packaging>
10-
10+
1111
<licenses>
1212
<license>
1313
<name>The Apache Software License, Version 2.0</name>
@@ -40,7 +40,7 @@
4040
<dependency>
4141
<groupId>org.junit.jupiter</groupId>
4242
<artifactId>junit-jupiter-engine</artifactId>
43-
<version>5.8.2</version>
43+
<version>5.12.2</version>
4444
<scope>test</scope>
4545
</dependency>
4646
</dependencies>

archetype/src/main/resources/archetype-resources/src/test/java/__analyzerName__Test.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,53 @@
1313
*/
1414
package ${package};
1515

16-
import java.io.File;
17-
import org.junit.jupiter.api.Test;
18-
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.AfterAll;
1917
import org.junit.jupiter.api.AfterEach;
2018
import org.junit.jupiter.api.BeforeAll;
21-
import org.junit.jupiter.api.AfterAll;
22-
import static org.junit.jupiter.api.Assertions.*;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2321
import org.owasp.dependencycheck.Engine;
2422
import org.owasp.dependencycheck.analyzer.AnalysisPhase;
2523
import org.owasp.dependencycheck.dependency.Dependency;
2624
import org.owasp.dependencycheck.utils.Settings;
2725

26+
import java.io.File;
27+
28+
import static org.junit.jupiter.api.Assertions.*;
29+
2830
/**
2931
* Test cases for ${analyzerName}
3032
*/
31-
public class ${analyzerName}Test {
32-
33+
class ${analyzerName}Test {
34+
3335
Settings settings = null;
34-
35-
public ${analyzerName}Test() {
36+
37+
${analyzerName}Test() {
3638
}
37-
39+
3840
@BeforeAll
39-
public static void setUpClass() {
41+
static void setUpClass() {
4042
}
41-
43+
4244
@AfterAll
43-
public static void tearDownClass() {
45+
static void tearDownClass() {
4446
}
45-
47+
4648
@BeforeEach
47-
public void setUp() {
49+
void setUp() {
4850
settings = new Settings();
4951
}
5052

5153
@AfterEach
52-
public void tearDown() {
54+
void tearDown() {
5355
settings.cleanup();
5456
}
5557

5658
/**
5759
* Test of accept method, of class ${analyzerName}.
5860
*/
5961
@Test
60-
public void testAccept() {
62+
void testAccept() {
6163
File pathname = new File("test.file");
6264
${analyzerName} instance = new ${analyzerName}();
6365
boolean expResult = true;
@@ -69,13 +71,13 @@ public void testAccept() {
6971
* Test of analyze method, of class ${analyzerName}.
7072
*/
7173
@Test
72-
public void testAnalyze() throws Exception {
74+
void testAnalyze() throws Exception {
7375
//The engine is generally null for most analyzer test cases but can be instantiated if needed.
7476
Engine engine = null;
7577
${analyzerName} instance = new ${analyzerName}();
7678
instance.initialize(settings);
7779
instance.prepare(engine);
78-
80+
7981
File file = new File(${analyzerName}.class.getClassLoader().getResource("test.file").toURI().getPath());
8082
Dependency dependency = new Dependency(file);
8183

@@ -87,7 +89,7 @@ public void testAnalyze() throws Exception {
8789
* Test of getName method, of class ${analyzerName}.
8890
*/
8991
@Test
90-
public void testGetName() {
92+
void testGetName() {
9193
${analyzerName} instance = new ${analyzerName}();
9294
String expResult = "${analyzerName}";
9395
String result = instance.getName();
@@ -98,7 +100,7 @@ public void testGetName() {
98100
* Test of getAnalysisPhase method, of class ${analyzerName}.
99101
*/
100102
@Test
101-
public void testGetAnalysisPhase() {
103+
void testGetAnalysisPhase() {
102104
${analyzerName} instance = new ${analyzerName}();
103105
AnalysisPhase expResult = AnalysisPhase.INFORMATION_COLLECTION;
104106
AnalysisPhase result = instance.getAnalysisPhase();
@@ -109,7 +111,7 @@ public void testGetAnalysisPhase() {
109111
* Test of initialize method, of class ${analyzerName}.
110112
*/
111113
@Test
112-
public void testInitialize() throws Exception {
114+
void testInitialize() throws Exception {
113115
${analyzerName} instance = new ${analyzerName}();
114116
instance.initialize(settings);
115117
}
@@ -118,7 +120,7 @@ public void testInitialize() throws Exception {
118120
* Test of close method, of class ${analyzerName}.
119121
*/
120122
@Test
121-
public void testClose() throws Exception {
123+
void testClose() throws Exception {
122124
${analyzerName} instance = new ${analyzerName}();
123125
instance.close();
124126
}
@@ -127,7 +129,7 @@ public void testClose() throws Exception {
127129
* Test of supportsParallelProcessing method, of class ${analyzerName}.
128130
*/
129131
@Test
130-
public void testSupportsParallelProcessing() {
132+
void testSupportsParallelProcessing() {
131133
${analyzerName} instance = new ${analyzerName}();
132134
boolean expResult = true;
133135
boolean result = instance.supportsParallelProcessing();
@@ -138,7 +140,7 @@ public void testSupportsParallelProcessing() {
138140
* Test of isEnabled method, of class ${analyzerName}.
139141
*/
140142
@Test
141-
public void testIsEnabled() {
143+
void testIsEnabled() {
142144
${analyzerName} instance = new ${analyzerName}();
143145
boolean expResult = true;
144146
boolean result = instance.isEnabled();

0 commit comments

Comments
 (0)