Skip to content

Commit 67acab0

Browse files
Migrate tests to JUnit5
* use JUnit5 annotations * use JUnit5 Assertions and Assumptions * remove public visibility from tests * remove junit-vintage-engine dependency
1 parent d87bda1 commit 67acab0

File tree

142 files changed

+2686
-3273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+2686
-3273
lines changed

commons-jcs3-core/pom.xml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@
9595
<artifactId>junit-jupiter</artifactId>
9696
<scope>test</scope>
9797
</dependency>
98-
<dependency>
99-
<groupId>org.junit.vintage</groupId>
100-
<artifactId>junit-vintage-engine</artifactId>
101-
<scope>test</scope>
102-
</dependency>
10398

10499
<!-- Exclude for now -->
105100
<!-- dependency>
@@ -171,7 +166,7 @@
171166
<java.security.manager>true</java.security.manager>
172167
<java.security.policy>${basedir}/src/test/conf/cache.policy</java.security.policy>
173168
<java.util.logging.config.file>${basedir}/src/test/test-conf/logging.properties</java.util.logging.config.file>
174-
</systemPropertyVariables>
169+
</systemPropertyVariables>
175170
</configuration>
176171
</execution>
177172
</executions>
@@ -189,7 +184,7 @@
189184
</plugin>
190185
</plugins>
191186
</build>
192-
187+
193188
<profiles>
194189
<profile>
195190
<id>testWithLog4j2</id>
@@ -216,7 +211,7 @@
216211
<systemPropertyVariables>
217212
<jcs.logSystem>log4j2</jcs.logSystem>
218213
<log4j.configurationFile>src/test/test-conf/log4j2-test.xml</log4j.configurationFile>
219-
</systemPropertyVariables>
214+
</systemPropertyVariables>
220215
</configuration>
221216
</execution>
222217
</executions>
@@ -249,7 +244,7 @@
249244
<java.security.manager>true</java.security.manager>
250245
<java.security.policy>${basedir}/src/test/conf/cache.policy</java.security.policy>
251246
<java.util.logging.config.file>${basedir}/src/test/test-conf/logging.properties</java.util.logging.config.file>
252-
</systemPropertyVariables>
247+
</systemPropertyVariables>
253248
</configuration>
254249
</execution>
255250
</executions>
Lines changed: 57 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package org.apache.commons.jcs3;
22

3-
import junit.extensions.ActiveTestSuite;
4-
import junit.framework.Test;
5-
import junit.framework.TestCase;
6-
73
/*
84
* Licensed to the Apache Software Foundation (ASF) under one
95
* or more contributor license agreements. See the NOTICE file
@@ -23,115 +19,78 @@
2319
* under the License.
2420
*/
2521

26-
import org.junit.Before;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.parallel.Execution;
25+
import org.junit.jupiter.api.parallel.ExecutionMode;
2726

2827
/**
2928
* Test which exercises the hierarchical removal when the cache is active.
3029
*/
31-
public class ConcurrentRemovalLoadTest
30+
@Execution(ExecutionMode.CONCURRENT)
31+
class ConcurrentRemovalLoadTest
3232
{
33-
/**
34-
* A unit test suite for JUnit. This verifies that we can remove hierarchically while the region
35-
* is active.
36-
* @return The test suite
37-
*/
38-
public static Test suite()
39-
{
40-
final ActiveTestSuite suite = new ActiveTestSuite();
4133

42-
suite.addTest(new TestCase("testRemoveCache1" )
43-
{
44-
@Override
45-
public void runTest()
46-
throws Exception
47-
{
48-
RemovalTestUtil.runTestPutThenRemoveCategorical( 0, 200 );
49-
}
50-
});
34+
@BeforeEach
35+
void setUp()
36+
{
37+
JCS.setConfigFilename( "/TestRemoval.ccf" );
38+
}
5139

52-
suite.addTest(new TestCase("testPutCache1" )
53-
{
54-
@Override
55-
public void runTest()
56-
throws Exception
57-
{
58-
RemovalTestUtil.runPutInRange( 300, 400 );
59-
}
60-
});
40+
@Test
41+
void testRemoveCache1_FirstRange()
42+
throws Exception
43+
{
44+
RemovalTestUtil.runTestPutThenRemoveCategorical( 0, 200 );
45+
}
6146

62-
suite.addTest(new TestCase("testPutCache2" )
63-
{
64-
@Override
65-
public void runTest()
66-
throws Exception
67-
{
68-
RemovalTestUtil.runPutInRange( 401, 600 );
69-
}
70-
});
47+
@Test
48+
void testPutCache1()
49+
throws Exception
50+
{
51+
RemovalTestUtil.runPutInRange( 300, 400 );
52+
}
7153

72-
// stomp on previous put
73-
suite.addTest(new TestCase("testPutCache3" )
74-
{
75-
@Override
76-
public void runTest()
77-
throws Exception
78-
{
79-
RemovalTestUtil.runPutInRange( 401, 600 );
80-
}
81-
});
54+
@Test
55+
void testPutCache2_FirstRange()
56+
throws Exception
57+
{
58+
RemovalTestUtil.runPutInRange( 401, 600 );
59+
}
8260

83-
suite.addTest(new TestCase("testRemoveCache1" )
84-
{
85-
@Override
86-
public void runTest()
87-
throws Exception
88-
{
89-
RemovalTestUtil.runTestPutThenRemoveCategorical( 601, 700 );
90-
}
91-
});
61+
@Test
62+
void testPutCache3_StompPreviousPut()
63+
throws Exception
64+
{
65+
RemovalTestUtil.runPutInRange( 401, 600 );
66+
}
9267

93-
suite.addTest(new TestCase("testRemoveCache1" )
94-
{
95-
@Override
96-
public void runTest()
97-
throws Exception
98-
{
99-
RemovalTestUtil.runTestPutThenRemoveCategorical( 701, 800 );
100-
}
101-
});
68+
@Test
69+
void testRemoveCache1_SecondRange()
70+
throws Exception
71+
{
72+
RemovalTestUtil.runTestPutThenRemoveCategorical( 601, 700 );
73+
}
10274

103-
suite.addTest(new TestCase("testRemoveCache1" )
104-
{
105-
@Override
106-
public void runTest()
107-
throws Exception
108-
{
109-
RemovalTestUtil.runTestPutThenRemoveCategorical( 901, 1000 );
110-
}
111-
});
75+
@Test
76+
void testRemoveCache1_ThirdRange()
77+
throws Exception
78+
{
79+
RemovalTestUtil.runTestPutThenRemoveCategorical( 701, 800 );
80+
}
11281

113-
suite.addTest(new TestCase("testPutCache2" )
114-
{
115-
// verify that there are no errors with concurrent gets.
116-
@Override
117-
public void runTest()
118-
throws Exception
119-
{
120-
RemovalTestUtil.runGetInRange( 0, 1000, false );
121-
}
122-
});
123-
return suite;
82+
@Test
83+
void testRemoveCache1_FourthRange()
84+
throws Exception
85+
{
86+
RemovalTestUtil.runTestPutThenRemoveCategorical( 901, 1000 );
12487
}
12588

126-
/**
127-
* Test setup
128-
* <p>
129-
* @throws Exception
130-
*/
131-
@Before
132-
public void setUp()
89+
@Test
90+
void testPutCache2_WithConcurrentGets()
13391
throws Exception
13492
{
135-
JCS.setConfigFilename( "/TestRemoval.ccf" );
93+
// verify that there are no errors with concurrent gets
94+
RemovalTestUtil.runGetInRange( 0, 1000, false );
13695
}
137-
}
96+
}

commons-jcs3-core/src/test/java/org/apache/commons/jcs3/JCSCacheElementRetrievalUnitTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919
* under the License.
2020
*/
2121

22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

2525
import org.apache.commons.jcs3.access.CacheAccess;
2626
import org.apache.commons.jcs3.engine.behavior.ICacheElement;
27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828

2929
/**
3030
*/
31-
public class JCSCacheElementRetrievalUnitTest
31+
class JCSCacheElementRetrievalUnitTest
3232
{
3333
/**
3434
*
3535
* @throws Exception
3636
*/
3737
@Test
38-
public void testSimpleElementRetrieval()
38+
void testSimpleElementRetrieval()
3939
throws Exception
4040
{
4141
final CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" );
@@ -44,10 +44,10 @@ public void testSimpleElementRetrieval()
4444

4545
final long now = System.currentTimeMillis();
4646
final ICacheElement<String, String> elem = jcs.getCacheElement( "test_key" );
47-
assertEquals( "Name wasn't right", "testCache1", elem.getCacheName() );
47+
assertEquals( "testCache1", elem.getCacheName(), "Name wasn't right" );
4848

4949
final long diff = now - elem.getElementAttributes().getCreateTime();
50-
assertTrue( "Create time should have been at or after the call", diff >= 0 );
50+
assertTrue( diff >= 0, "Create time should have been at or after the call" );
5151

5252
}
5353
}

commons-jcs3-core/src/test/java/org/apache/commons/jcs3/JCSConcurrentCacheAccessUnitTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.apache.commons.jcs3;
22

3-
import static org.junit.Assert.assertEquals;
4-
53
/*
64
* Licensed to the Apache Software Foundation (ASF) under one
75
* or more contributor license agreements. See the NOTICE file
@@ -21,20 +19,23 @@
2119
* under the License.
2220
*/
2321

22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
2424
import java.util.List;
2525
import java.util.concurrent.CopyOnWriteArrayList;
2626
import java.util.concurrent.atomic.AtomicInteger;
2727

2828
import org.apache.commons.jcs3.access.GroupCacheAccess;
2929
import org.apache.commons.jcs3.access.exception.CacheException;
30-
import org.junit.After;
31-
import org.junit.Before;
32-
import org.junit.Test;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3333

3434
/**
3535
* Test Case for JCS-73, modeled after the Groovy code by Alexander Kleymenov
3636
*/
37-
public class JCSConcurrentCacheAccessUnitTest{
37+
class JCSConcurrentCacheAccessUnitTest
38+
{
3839
/**
3940
* Worker thread
4041
*/
@@ -131,29 +132,30 @@ public void run()
131132
*/
132133
protected List<String> valueMismatchList;
133134

134-
@Before
135-
public void setUp() throws Exception
135+
@BeforeEach
136+
void setUp()
137+
throws Exception
136138
{
137139
JCS.setConfigFilename( "/TestJCS-73.ccf" );
138140
cache = JCS.getGroupCacheInstance( "cache" );
139141
errcount = new AtomicInteger();
140142
valueMismatchList = new CopyOnWriteArrayList<>();
141143
}
142144

143-
@After
144-
public void tearDown()
145+
@AfterEach
146+
void tearDown()
145147
throws Exception
146148
{
147149
cache.clear();
148150
cache.dispose();
149151
}
150152

151-
/**
153+
/**
152154
*
153155
* @throws Exception
154156
*/
155157
@Test
156-
public void testConcurrentAccess()
158+
void testConcurrentAccess()
157159
throws Exception
158160
{
159161
final Worker[] worker = new Worker[THREADS];
@@ -169,12 +171,12 @@ public void testConcurrentAccess()
169171
worker[i].join();
170172
}
171173

172-
assertEquals("Error count should be 0", 0, errcount.intValue());
174+
assertEquals( 0, errcount.intValue(), "Error count should be 0" );
173175
for (final String msg : valueMismatchList)
174176
{
175177
System.out.println(msg);
176178
}
177-
assertEquals("Value mismatch count should be 0", 0, valueMismatchList.size());
179+
assertEquals( 0, valueMismatchList.size(), "Value mismatch count should be 0" );
178180
}
179181

180182
}

0 commit comments

Comments
 (0)