Skip to content

Commit 08d1fab

Browse files
Replace TestNG with JUnit5 (#117)
* Add 8 to matrix for testing * Replace testng with junit5
1 parent 6206cf1 commit 08d1fab

23 files changed

+469
-453
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
matrix:
2828
distribution: ["zulu", "adopt"]
29-
java: ["11"]
29+
java: ["8", "11"]
3030

3131
steps:
3232
- name: Checkout repository

pom.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<lombok.version>1.18.22</lombok.version>
4646
<slf4j.version>1.7.30</slf4j.version>
4747
<maven.checkstyle.version>3.1.0</maven.checkstyle.version>
48+
<junit.jupiter.version>5.9.2</junit.jupiter.version>
4849
</properties>
4950

5051
<dependencies>
@@ -104,9 +105,15 @@
104105
<scope>test</scope>
105106
</dependency>
106107
<dependency>
107-
<groupId>org.testng</groupId>
108-
<artifactId>testng</artifactId>
109-
<version>7.7.0</version>
108+
<groupId>org.junit.jupiter</groupId>
109+
<artifactId>junit-jupiter-engine</artifactId>
110+
<version>${junit.jupiter.version}</version>
111+
<scope>test</scope>
112+
</dependency>
113+
<dependency>
114+
<groupId>org.junit.jupiter</groupId>
115+
<artifactId>junit-jupiter-params</artifactId>
116+
<version>${junit.jupiter.version}</version>
110117
<scope>test</scope>
111118
</dependency>
112119
<dependency>
@@ -122,6 +129,7 @@
122129
<scope>test</scope>
123130
</dependency>
124131
<dependency>
132+
<!-- todo: do we need this? -->
125133
<groupId>io.rest-assured</groupId>
126134
<artifactId>rest-assured</artifactId>
127135
<version>4.3.3</version>
@@ -236,6 +244,11 @@
236244
</execution>
237245
</executions>
238246
</plugin>
247+
<plugin>
248+
<groupId>org.apache.maven.plugins</groupId>
249+
<artifactId>maven-surefire-plugin</artifactId>
250+
<version>2.22.0</version>
251+
</plugin>
239252
</plugins>
240253
</build>
241254

src/test/java/com/flagsmith/FlagsmithApiWrapperCachingTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.flagsmith;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
35
import static org.mockito.ArgumentMatchers.any;
46
import static org.mockito.ArgumentMatchers.anyBoolean;
57
import static org.mockito.ArgumentMatchers.anyString;
68
import static org.mockito.Mockito.mock;
79
import static org.mockito.Mockito.times;
810
import static org.mockito.Mockito.verify;
911
import static org.mockito.Mockito.when;
10-
import static org.testng.Assert.*;
1112

1213
import com.fasterxml.jackson.databind.node.ObjectNode;
1314
import com.flagsmith.config.FlagsmithCacheConfig;
@@ -28,11 +29,11 @@
2829
import okhttp3.Request;
2930
import okhttp3.RequestBody;
3031
import okhttp3.mock.MockInterceptor;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.BeforeEach;
3134
import org.mockito.ArgumentCaptor;
32-
import org.testng.annotations.BeforeMethod;
33-
import org.testng.annotations.Test;
3435

35-
@Test(groups = "unit")
36+
3637
public class FlagsmithApiWrapperCachingTest {
3738
private final String API_KEY = "OUR_API_KEY";
3839
private final String BASE_URL = "https://unit-test.com";
@@ -45,7 +46,7 @@ public class FlagsmithApiWrapperCachingTest {
4546
private MockInterceptor interceptor;
4647
private RequestProcessor requestProcessor;
4748

48-
@BeforeMethod(groups = "unit")
49+
@BeforeEach
4950
public void init() {
5051
flagsmithCacheImpl = mock(FlagsmithCacheConfig.FlagsmithCacheImpl.class);
5152

@@ -64,13 +65,13 @@ public void init() {
6465
flagsmithAPIWrapper.setRequestor(requestProcessor);
6566
}
6667

67-
@Test(groups = "unit")
68+
@Test
6869
public void getCache_returnsInternalCache() {
6970
final FlagsmithCache actualInternalCache = flagsmithAPIWrapper.getCache();
7071
assertEquals(flagsmithCacheImpl, actualInternalCache);
7172
}
7273

73-
@Test(groups = "unit")
74+
@Test
7475
public void getFeatureFlags_envFlags_cacheEnabled_dontFetchFlagsWhenInCache() {
7576
// Arrange
7677
final String cacheKey = "cacheKey";
@@ -89,7 +90,7 @@ public void getFeatureFlags_envFlags_cacheEnabled_dontFetchFlagsWhenInCache() {
8990
assertEquals(flagsAndTraits, actualFeatureFlags);
9091
}
9192

92-
@Test(groups = "unit")
93+
@Test
9394
public void getFeatureFlags_fetchFlagsFromFlagsmithAndStoreThemInCache() {
9495
final String cacheKey = "cacheKey";
9596
when(flagsmithCacheImpl.getEnvFlagsCacheKey()).thenReturn(cacheKey);
@@ -110,7 +111,7 @@ public void getFeatureFlags_fetchFlagsFromFlagsmithAndStoreThemInCache() {
110111
assertEquals(1, cache.estimatedSize());
111112
}
112113

113-
@Test(groups = "unit")
114+
@Test
114115
public void getFeatureFlags_fetchFlagsFromCacheAndNotFromFlagsmith() {
115116
// Arrange
116117
final String cacheKey = "cacheKey";
@@ -127,7 +128,7 @@ public void getFeatureFlags_fetchFlagsFromCacheAndNotFromFlagsmith() {
127128
assertEquals(newFlagsList(flagsAndTraits), actualFeatureFlags);
128129
}
129130

130-
@Test(groups = "unit")
131+
@Test
131132
public void identifyUserWithTraits_nullUser() {
132133
// Act
133134
assertThrows(IllegalArgumentException.class,
@@ -138,7 +139,7 @@ public void identifyUserWithTraits_nullUser() {
138139
assertEquals(0, cache.estimatedSize());
139140
}
140141

141-
@Test(groups = "unit")
142+
@Test
142143
public void identifyUserWithTraits_nullUserIdentifier() {
143144
// Act
144145
assertThrows(IllegalArgumentException.class,
@@ -149,7 +150,7 @@ public void identifyUserWithTraits_nullUserIdentifier() {
149150
assertEquals(0, cache.estimatedSize());
150151
}
151152

152-
@Test(groups = "unit")
153+
@Test
153154
public void identifyUserWithTraits_fetchFlagsFromFlagsmithAndStoreThemInCache_whenCacheEmpty() {
154155
// Arrange
155156
String identifier = "test-user";
@@ -169,7 +170,7 @@ public void identifyUserWithTraits_fetchFlagsFromFlagsmithAndStoreThemInCache_wh
169170
assertEquals(newFlagsList(new ArrayList<>()), actualUserFlagsAndTraits);
170171
}
171172

172-
@Test(groups = "unit")
173+
@Test
173174
public void testGetFeatureFlags_ReturnsFeatureFlagsFromApi_IfCacheButNoEnvCacheKey() {
174175
// Given
175176
when(flagsmithCacheImpl.getEnvFlagsCacheKey()).thenReturn(null);
@@ -185,7 +186,7 @@ public void testGetFeatureFlags_ReturnsFeatureFlagsFromApi_IfCacheButNoEnvCacheK
185186
assertEquals(flags, Flags.fromFeatureStateModels(featureStateModels, null));
186187
}
187188

188-
@Test(groups = "unit")
189+
@Test
189190
public void verifyRequestBody() {
190191
String identifier = "test-user";
191192
final ArrayList<TraitModel> traits = new ArrayList<>();

src/test/java/com/flagsmith/FlagsmithApiWrapperTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import static org.mockito.Mockito.mock;
1010
import static org.mockito.Mockito.times;
1111
import static org.mockito.Mockito.verify;
12-
import static org.testng.Assert.assertEquals;
13-
import static org.testng.Assert.assertNull;
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertNull;
1414

1515
import com.fasterxml.jackson.core.JsonProcessingException;
1616
import com.fasterxml.jackson.core.type.TypeReference;
@@ -37,10 +37,10 @@
3737
import okhttp3.ResponseBody;
3838
import okhttp3.mock.MockInterceptor;
3939
import org.bouncycastle.ocsp.Req;
40-
import org.testng.annotations.BeforeMethod;
41-
import org.testng.annotations.Test;
40+
import org.junit.jupiter.api.BeforeEach;
41+
import org.junit.jupiter.api.Test;
42+
4243

43-
@Test(groups = "unit")
4444
public class FlagsmithApiWrapperTest {
4545

4646
private final String API_KEY = "OUR_API_KEY";
@@ -51,7 +51,7 @@ public class FlagsmithApiWrapperTest {
5151
private FlagsmithConfig defaultConfig;
5252
private MockInterceptor interceptor;
5353

54-
@BeforeMethod(groups = "unit")
54+
@BeforeEach
5555
public void init() {
5656
flagsmithLogger = mock(FlagsmithLogger.class);
5757
doThrow(new FlagsmithException("error Response")).when(flagsmithLogger)
@@ -65,7 +65,7 @@ public void init() {
6565
sut = new FlagsmithApiWrapper(defaultConfig, null, flagsmithLogger, API_KEY);
6666
}
6767

68-
@Test(groups = "unit")
68+
@Test
6969
public void getFeatureFlags_noUser_success() throws JsonProcessingException {
7070
// Arrange
7171
interceptor.addRule()
@@ -82,7 +82,7 @@ public void getFeatureFlags_noUser_success() throws JsonProcessingException {
8282
verify(flagsmithLogger, times(0)).httpError(any(), any(IOException.class), anyBoolean());
8383
}
8484

85-
@Test(groups = "unit")
85+
@Test
8686
public void getFeatureFlags_noUser_fail() {
8787
// Arrange
8888
interceptor.addRule()
@@ -99,7 +99,7 @@ public void getFeatureFlags_noUser_fail() {
9999
verify(flagsmithLogger, times(0)).httpError(any(), any(IOException.class), anyBoolean());
100100
}
101101

102-
@Test(groups = "unit")
102+
@Test
103103
public void identifyUserWithTraits_success() throws JsonProcessingException {
104104
// Arrange
105105
final List<TraitModel> traits = new ArrayList<TraitModel>(Arrays.asList(new TraitModel()));
@@ -124,7 +124,7 @@ public void identifyUserWithTraits_success() throws JsonProcessingException {
124124
verify(flagsmithLogger, times(0)).httpError(any(), any(IOException.class), anyBoolean());
125125
}
126126

127-
@Test(groups = "unit")
127+
@Test
128128
public void identifyUserWithTraits_fail() {
129129
// Arrange
130130
final List<TraitModel> traits = new ArrayList<TraitModel>(Arrays.asList(new TraitModel()));
@@ -142,7 +142,7 @@ public void identifyUserWithTraits_fail() {
142142
verify(flagsmithLogger, times(0)).httpError(any(), any(IOException.class), anyBoolean());
143143
}
144144

145-
@Test(groups = "unit")
145+
@Test
146146
public void testClose_ClosesRequestProcessor() {
147147
// Given
148148
RequestProcessor mockedRequestProcessor = mock(RequestProcessor.class);
@@ -156,7 +156,7 @@ public void testClose_ClosesRequestProcessor() {
156156
verify(mockedRequestProcessor, times(1)).close();
157157
}
158158

159-
@Test(groups = "unit")
159+
@Test
160160
public void testClose_ClosesAnalyticsProcessor() {
161161
// Given
162162
AnalyticsProcessor mockedAnalyticsProcessor = mock(AnalyticsProcessor.class);

0 commit comments

Comments
 (0)