Skip to content

Commit 07840c4

Browse files
committed
refactor: Migrate unit tests to JUnit 5
1 parent f5bf637 commit 07840c4

14 files changed

+196
-189
lines changed

pom.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@
128128
<artifactId>DynamoDBLocal</artifactId>
129129
<scope>test</scope>
130130
</dependency>
131-
<dependency>
132-
<groupId>junit</groupId>
133-
<artifactId>junit</artifactId>
134-
<scope>test</scope>
135-
</dependency>
136131
</dependencies>
137132

138133
<build>
@@ -160,7 +155,7 @@
160155
<plugin>
161156
<groupId>org.jacoco</groupId>
162157
<artifactId>jacoco-maven-plugin</artifactId>
163-
<version>0.7.7.201606060606</version>
158+
<version>0.8.8</version>
164159
<executions>
165160
<execution>
166161
<id>prepare-agent</id>
@@ -178,7 +173,7 @@
178173
<plugin>
179174
<groupId>org.sonatype.plugins</groupId>
180175
<artifactId>nexus-staging-maven-plugin</artifactId>
181-
<version>1.6.7</version>
176+
<version>1.6.13</version>
182177
<extensions>true</extensions>
183178
<configuration>
184179
<serverId>ossrh</serverId>

src/test/java/com/dasburo/spring/cache/dynamo/DynamoCacheManagerTest.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
*/
1515
package com.dasburo.spring.cache.dynamo;
1616

17-
import org.junit.Assert;
18-
import org.junit.Before;
19-
import org.junit.ClassRule;
20-
import org.junit.Test;
21-
import org.junit.runner.RunWith;
17+
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.extension.ExtendWith;
2220
import org.springframework.beans.factory.annotation.Autowired;
2321
import org.springframework.cache.Cache;
2422
import org.springframework.test.context.ContextConfiguration;
25-
import org.springframework.test.context.junit4.SpringRunner;
23+
import org.springframework.test.context.junit.jupiter.SpringExtension;
2624
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
2725

2826
import java.util.ArrayList;
@@ -32,27 +30,25 @@
3230
import static org.hamcrest.CoreMatchers.hasItem;
3331
import static org.hamcrest.CoreMatchers.instanceOf;
3432
import static org.hamcrest.MatcherAssert.assertThat;
33+
import static org.junit.jupiter.api.Assertions.*;
3534

3635
/**
3736
* Unit tests for {@link DynamoCacheManager}.
3837
*
3938
* @author Georg Zimmermann
4039
*/
41-
@RunWith(SpringRunner.class)
40+
@ExtendWith({SpringExtension.class, TestDbCreationExtension.class})
4241
@ContextConfiguration(classes = TestConfiguration.class)
4342
public class DynamoCacheManagerTest {
4443

4544
private static final String CACHE_NAME = "cache";
4645

47-
@ClassRule
48-
public static TestDbCreationRule dynamoDB = new TestDbCreationRule();
49-
5046
@Autowired
5147
private DynamoDbClient dynamoTemplate;
5248

5349
private DynamoCacheManager manager;
5450

55-
@Before
51+
@BeforeEach
5652
public void setup() {
5753
DynamoCacheBuilder defaultCacheBuilder = DynamoCacheBuilder.newInstance(CACHE_NAME, dynamoTemplate);
5854
this.manager = new DynamoCacheManager(Collections.singletonList(defaultCacheBuilder));
@@ -70,8 +66,8 @@ public void loadCaches() {
7066

7167
final DynamoCacheManager manager = new DynamoCacheManager(initialCaches);
7268
final Collection<? extends Cache> caches = manager.loadCaches();
73-
Assert.assertNotNull(caches);
74-
Assert.assertEquals(1, caches.size());
69+
assertNotNull(caches);
70+
assertEquals(1, caches.size());
7571
}
7672

7773
/**
@@ -80,12 +76,12 @@ public void loadCaches() {
8076
@Test
8177
public void cache() {
8278
final Cache cache = manager.getCache(CACHE_NAME);
83-
Assert.assertNotNull(cache);
84-
Assert.assertEquals(CACHE_NAME, cache.getName());
79+
assertNotNull(cache);
80+
assertEquals(CACHE_NAME, cache.getName());
8581
assertThat(cache, instanceOf(DynamoCache.class));
8682

8783
final DynamoCache dynamoCache = (DynamoCache) cache;
88-
Assert.assertEquals(dynamoCache.getNativeCache(), dynamoTemplate);
84+
assertEquals(dynamoCache.getNativeCache(), dynamoTemplate);
8985
}
9086

9187
/**
@@ -94,19 +90,19 @@ public void cache() {
9490
@Test
9591
public void getCache() {
9692
final Cache cache = manager.getCache(CACHE_NAME);
97-
Assert.assertNotNull(cache);
93+
assertNotNull(cache);
9894

9995
final Cache invalidCache = manager.getCache("invalid");
100-
Assert.assertNull(invalidCache);
96+
assertNull(invalidCache);
10197
}
10298

10399
/**
104100
* Test for {@link DynamoCacheManager#getCacheNames()}
105101
*/
106102
@Test
107103
public void getCacheNames() {
108-
Assert.assertNotNull(manager.getCacheNames());
109-
Assert.assertEquals(1, manager.getCacheNames().size());
104+
assertNotNull(manager.getCacheNames());
105+
assertEquals(1, manager.getCacheNames().size());
110106
assertThat(manager.getCacheNames(), hasItem(CACHE_NAME));
111107
}
112108

0 commit comments

Comments
 (0)