Skip to content

Commit 9e84516

Browse files
feat: fix test run for java 19
1 parent 1ecbd4a commit 9e84516

17 files changed

+138
-90
lines changed

sdk-java/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ dependencies {
2121
implementation 'org.json:json:20250107'
2222
implementation 'com.google.code.findbugs:jsr305:3.0.2'
2323

24-
testImplementation 'junit:junit:4.13.1'
25-
testImplementation 'org.mockito:mockito-core:2.8.9'
26-
testImplementation "org.powermock:powermock-core:${POWERMOCK_VERSION}"
27-
testImplementation "org.powermock:powermock-module-junit4:${POWERMOCK_VERSION}"
24+
testImplementation(platform("org.mockito:mockito-bom:5.12.0"))
25+
testImplementation("org.mockito:mockito-core")
26+
testRuntimeOnly("net.bytebuddy:byte-buddy-agent")
27+
testImplementation("junit:junit:4.13.2")
2828
//testImplementation 'com.squareup.okhttp3:mockwebserver:3.7.0'
2929
}
3030

sdk-java/src/test/java/ly/count/sdk/java/internal/EventImplTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@RunWith(JUnit4.class)
1616
public class EventImplTests {
1717

18-
Log L = mock(Log.class);
18+
Log L = TestUtils.getLogger();
1919

2020
/**
2121
* Constructor of EventImpl class.

sdk-java/src/test/java/ly/count/sdk/java/internal/EventQueueTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
import static ly.count.sdk.java.internal.SDKStorage.FILE_NAME_SEPARATOR;
2121
import static ly.count.sdk.java.internal.TestUtils.validateEvent;
2222
import static org.mockito.ArgumentMatchers.anyCollection;
23-
import static org.mockito.Mockito.mock;
2423
import static org.mockito.Mockito.never;
2524
import static org.mockito.Mockito.spy;
2625
import static org.mockito.Mockito.verify;
2726

2827
@RunWith(JUnit4.class)
2928
public class EventQueueTests {
3029

31-
Log L = mock(Log.class);
30+
Log L = TestUtils.getLogger();
3231

3332
EventQueue eventQueue;
3433

@@ -96,7 +95,7 @@ public void writeEventQueueToStorage() {
9695
@Test
9796
public void writeEventQueueToStorage_emptyCache() {
9897
eventQueue = spy(EventQueue.class);
99-
eventQueue.L = mock(Log.class);
98+
eventQueue.L = TestUtils.getLogger();
10099
eventQueue.eventQueueMemoryCache = new ArrayList<>();
101100

102101
eventQueue.writeEventQueueToStorage();

sdk-java/src/test/java/ly/count/sdk/java/internal/ImmediateRequestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@RunWith(JUnit4.class)
1616
public class ImmediateRequestTest {
17-
Log L = mock(Log.class);
17+
Log L = TestUtils.getLogger();
1818

1919
@After
2020
public void stop() {

sdk-java/src/test/java/ly/count/sdk/java/internal/JsonFileStorageTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@RunWith(JUnit4.class)
1717
public class JsonFileStorageTests {
1818

19-
private static final Log L = Mockito.mock(Log.class);
19+
private static Log L = TestUtils.getLogger();
2020
JsonFileStorage storage;
2121
static final String JSON_FILE_NAME = "test.json";
2222

@@ -78,6 +78,7 @@ public void readJsonFile_emptyJsonFile() {
7878
@Test
7979
public void readJsonFile_IOException() throws IOException {
8080
File file = Mockito.mock(File.class);
81+
L = Mockito.spy(L);
8182
Mockito.doThrow(new IOException("Simulated IOException")).when(file).createNewFile();
8283

8384
storage = new JsonFileStorage(file, L);

sdk-java/src/test/java/ly/count/sdk/java/internal/LogTests.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
package ly.count.sdk.java.internal;
22

3+
import ly.count.sdk.java.Config;
34
import org.junit.After;
4-
import org.junit.Assert;
55
import org.junit.Before;
66
import org.junit.Test;
7-
import org.junit.runner.RunWith;
8-
import org.junit.runners.JUnit4;
9-
import org.powermock.reflect.Whitebox;
10-
11-
import ly.count.sdk.java.Config;
12-
13-
import static ly.count.sdk.java.Config.LoggingLevel.DEBUG;
14-
import static ly.count.sdk.java.Config.LoggingLevel.ERROR;
15-
import static ly.count.sdk.java.Config.LoggingLevel.INFO;
16-
import static ly.count.sdk.java.Config.LoggingLevel.OFF;
17-
import static ly.count.sdk.java.Config.LoggingLevel.WARN;
18-
import static org.mockito.Mockito.mock;
19-
import static org.mockito.Mockito.never;
20-
import static org.mockito.Mockito.times;
21-
import static org.mockito.Mockito.verify;
227

23-
@RunWith(JUnit4.class)
248
public class LogTests {
259
private static final String message = "message";
2610
private static final Throwable exception = new IllegalStateException("IAS");

sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void beforeTest() {
7171
*/
7272
private void initStorage() {
7373
InternalConfig config = (new InternalConfig(TestUtils.getBaseConfig()));
74-
config.setLogger(mock(Log.class));
74+
config.setLogger(TestUtils.getLogger());
7575
storageProvider = new SDKStorage().init(config);
7676
}
7777

@@ -90,7 +90,7 @@ public void afterTest() {
9090
*/
9191
@Test
9292
public void migrationHelper_defaults() {
93-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
93+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
9494
Assert.assertEquals(-1, migrationHelper.currentDataModelVersion);//validate the default version value
9595
Assert.assertNotNull(migrationHelper.logger);
9696
Assert.assertNull(migrationHelper.storageProvider);
@@ -105,7 +105,7 @@ public void migrationHelper_defaults() {
105105
@Test
106106
public void setupMigrations_freshInstall() {
107107
initStorage(); // to initialize json storage
108-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
108+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
109109
migrationHelper.setupMigrations(storageProvider);
110110
Assert.assertEquals(expectedLatestSchemaVersion, migrationHelper.currentDataModelVersion);
111111
}
@@ -120,7 +120,7 @@ public void setupMigrations_legacyState() {
120120
TestUtils.createFile("test"); //mock a sdk file, to simulate storage is not empty
121121
initStorage(); // to initialize json storage after mock sdk file is created
122122

123-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
123+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
124124
migrationHelper.setupMigrations(storageProvider);
125125
Assert.assertEquals(0, migrationHelper.currentDataModelVersion);
126126
}
@@ -135,7 +135,7 @@ public void setupMigrations_latestVersion() throws IOException {
135135
setDataVersionInConfigFile(expectedLatestSchemaVersion);
136136
initStorage(); // to initialize json storage after data version is set to expectedLatestVersion
137137

138-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
138+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
139139
migrationHelper.logger = spy(migrationHelper.logger);
140140
migrationHelper.setupMigrations(storageProvider);
141141
Assert.assertEquals(expectedLatestSchemaVersion, migrationHelper.currentDataModelVersion);
@@ -153,7 +153,7 @@ public void applyMigrations_legacyToLatest() {
153153
TestUtils.createFile("test"); //mock a sdk file, to simulate storage is not empty
154154
initStorage(); // to initialize json storage after mock sdk file is created
155155

156-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
156+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
157157
migrationHelper.setupMigrations(storageProvider);
158158
Assert.assertEquals(0, migrationHelper.currentDataModelVersion); //legacy state
159159
Map<String, Object> migrationParams = new ConcurrentHashMap<>();
@@ -175,7 +175,7 @@ public void applyMigrations_latestToLatest() throws IOException {
175175
setDataVersionInConfigFile(expectedLatestSchemaVersion); //set data version to latest
176176
initStorage(); // to initialize json storage after data version is set to 1
177177

178-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
178+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
179179
migrationHelper.setupMigrations(storageProvider);
180180
Assert.assertEquals(expectedLatestSchemaVersion, migrationHelper.currentDataModelVersion); //latest state
181181
//run migration helper apply
@@ -195,7 +195,7 @@ public void applyMigrations_0to1() throws IOException {
195195
Files.write(TestUtils.createFile("config_0").toPath(), MOCK_OLD_CONFIG_FILE_sdkGenId); //mock a sdk config file, to simulate storage is not empty
196196
initStorage(); // to initialize json storage after mock sdk file is created
197197

198-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
198+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
199199
migrationHelper.setupMigrations(storageProvider);
200200
Assert.assertEquals(0, migrationHelper.currentDataModelVersion); //legacy state
201201

@@ -294,7 +294,7 @@ public void applyMigrations_1to2_nothingToMigrate() throws IOException {
294294
Map<String, Object> migrationParams = new ConcurrentHashMap<>();
295295
migrationParams.put("sdk_path", TestUtils.getTestSDirectory());
296296

297-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
297+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
298298
migrationHelper.setupMigrations(storageProvider);
299299
Assert.assertEquals(1, migrationHelper.currentDataModelVersion);
300300
migrationHelper.logger = Mockito.spy(migrationHelper.logger);
@@ -314,7 +314,7 @@ public void applyMigrations_1to2_nullMigrationParams() throws IOException {
314314
setDataVersionInConfigFile(1); // set previous data version
315315
initStorage();
316316

317-
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
317+
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
318318
migrationHelper.setupMigrations(storageProvider);
319319
Assert.assertEquals(1, migrationHelper.currentDataModelVersion);
320320
migrationHelper.logger = Mockito.spy(migrationHelper.logger);

sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleFeedbackTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@RunWith(JUnit4.class)
2626
public class ModuleFeedbackTests {
2727

28-
Log L = mock(Log.class);
28+
Log L = TestUtils.getLogger();
2929

3030
@Before
3131
public void beforeTest() {

sdk-java/src/test/java/ly/count/sdk/java/internal/MultiThreadingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void multiThread() throws BrokenBarrierException, InterruptedException {
7474
}
7575

7676
gate.await();
77-
Storage.await(Mockito.mock(Log.class));
77+
Storage.await(TestUtils.getLogger());
7878

7979
for (Thread t : runs) {
8080
t.join();

sdk-java/src/test/java/ly/count/sdk/java/internal/RemoteConfigValueStoreTests.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class RemoteConfigValueStoreTests {
1919
*/
2020
@Test
2121
public void constructor_defaults() {
22-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(new JSONObject(), false, Mockito.mock(Log.class));
22+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(new JSONObject(), false, TestUtils.getLogger());
2323
Assert.assertEquals(RemoteConfigValueStore.keyValue, "v");
2424
Assert.assertEquals(RemoteConfigValueStore.keyCacheFlag, "c");
2525
Assert.assertEquals(RemoteConfigValueStore.cacheValCached, 0);
@@ -35,7 +35,7 @@ public void constructor_defaults() {
3535
*/
3636
@Test
3737
public void cacheClearValues_cachingDisabled() {
38-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), false, Mockito.mock(Log.class));
38+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), false, TestUtils.getLogger());
3939
Assert.assertEquals(2, rcvs.getAllValues().size());
4040
rcvs.cacheClearValues();
4141
Assert.assertEquals(rcvs.values.length(), 0);
@@ -48,7 +48,7 @@ public void cacheClearValues_cachingDisabled() {
4848
*/
4949
@Test(expected = NullPointerException.class)
5050
public void cacheClearValues_nullRcValues() {
51-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, false, Mockito.mock(Log.class));
51+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, false, TestUtils.getLogger());
5252
rcvs.cacheClearValues();
5353
}
5454

@@ -59,7 +59,7 @@ public void cacheClearValues_nullRcValues() {
5959
*/
6060
@Test
6161
public void cacheClearValues_cachingEnabled() {
62-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
62+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
6363
Assert.assertEquals(2, rcvs.getAllValues().size());
6464
rcvs.cacheClearValues();
6565
Assert.assertEquals(2, rcvs.getAllValues().size());
@@ -74,7 +74,7 @@ public void cacheClearValues_cachingEnabled() {
7474
*/
7575
@Test
7676
public void cacheClearValues_garbageJson() {
77-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, Mockito.mock(Log.class));
77+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, TestUtils.getLogger());
7878
rcvs.L = Mockito.spy(rcvs.L);
7979
rcvs.cacheClearValues();
8080
Mockito.verify(rcvs.L, Mockito.times(1)).w("[RemoteConfigValueStore] cacheClearValues, stored entry was not a JSON object, key:[" + TestUtils.keysValues[0] + "] value:[garbage]");
@@ -89,7 +89,7 @@ public void cacheClearValues_garbageJson() {
8989
*/
9090
@Test
9191
public void mergeValues_fullUpdate() {
92-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
92+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
9393
Assert.assertEquals(2, rcvs.getAllValues().size());
9494
Assert.assertEquals(TestUtils.keysValues[1], rcvs.getValue(TestUtils.keysValues[0]).value);
9595
rcvs.mergeValues(newRCValues(), true);
@@ -105,7 +105,7 @@ public void mergeValues_fullUpdate() {
105105
*/
106106
@Test
107107
public void mergeValues_notFullUpdate() {
108-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
108+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
109109
Assert.assertEquals(2, rcvs.getAllValues().size());
110110
Assert.assertEquals(TestUtils.keysValues[1], rcvs.getValue(TestUtils.keysValues[0]).value);
111111
rcvs.mergeValues(newRCValues(), false);
@@ -121,7 +121,7 @@ public void mergeValues_notFullUpdate() {
121121
*/
122122
@Test(expected = NullPointerException.class)
123123
public void mergeValues_nullNewRcValues() {
124-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
124+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
125125
Assert.assertEquals(2, rcvs.getAllValues().size());
126126
rcvs.mergeValues(null, false);
127127
}
@@ -133,7 +133,7 @@ public void mergeValues_nullNewRcValues() {
133133
*/
134134
@Test(expected = NullPointerException.class)
135135
public void mergeValues_nullRcValues() {
136-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, Mockito.mock(Log.class));
136+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, TestUtils.getLogger());
137137
rcvs.mergeValues(newRCValues(), false);
138138
}
139139

@@ -144,7 +144,7 @@ public void mergeValues_nullRcValues() {
144144
*/
145145
@Test
146146
public void getValue_nullRcValues() {
147-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, Mockito.mock(Log.class));
147+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, TestUtils.getLogger());
148148
rcvs.L = Mockito.spy(rcvs.L);
149149
Assert.assertNull(rcvs.getValue(TestUtils.keysValues[0]).value);
150150
Mockito.verify(rcvs.L, Mockito.times(1)).e(Mockito.anyString());
@@ -157,7 +157,7 @@ public void getValue_nullRcValues() {
157157
*/
158158
@Test
159159
public void getValue() {
160-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
160+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
161161
Assert.assertEquals(TestUtils.keysValues[1], rcvs.getValue(TestUtils.keysValues[0]).value);
162162
}
163163

@@ -168,7 +168,7 @@ public void getValue() {
168168
*/
169169
@Test
170170
public void getValue_notExist() {
171-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
171+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
172172
Assert.assertNull(rcvs.getValue(TestUtils.keysValues[5]).value);
173173
}
174174

@@ -179,7 +179,7 @@ public void getValue_notExist() {
179179
*/
180180
@Test
181181
public void getValue_garbageJson() {
182-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, Mockito.mock(Log.class));
182+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, TestUtils.getLogger());
183183
Assert.assertEquals(1, rcvs.values.length());
184184
Assert.assertNull(rcvs.getValue(TestUtils.keysValues[0]).value);
185185
}
@@ -191,7 +191,7 @@ public void getValue_garbageJson() {
191191
*/
192192
@Test
193193
public void getAllValues() {
194-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
194+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
195195
Assert.assertEquals(2, rcvs.getAllValues().size());
196196
Assert.assertEquals(2, rcvs.values.length());
197197
}
@@ -203,7 +203,7 @@ public void getAllValues() {
203203
*/
204204
@Test(expected = NullPointerException.class)
205205
public void getAllValues_nullRcValues() {
206-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, Mockito.mock(Log.class));
206+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, TestUtils.getLogger());
207207
rcvs.getAllValues();
208208
}
209209

@@ -214,7 +214,7 @@ public void getAllValues_nullRcValues() {
214214
*/
215215
@Test
216216
public void getAllValues_garbageJson() {
217-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, Mockito.mock(Log.class));
217+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, TestUtils.getLogger());
218218
Assert.assertEquals(0, rcvs.getAllValues().size());
219219
Assert.assertEquals(1, rcvs.values.length());
220220
}
@@ -226,7 +226,7 @@ public void getAllValues_garbageJson() {
226226
*/
227227
@Test
228228
public void getAllValues_garbageCacheKey() {
229-
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson("garbage"), true, Mockito.mock(Log.class));
229+
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson("garbage"), true, TestUtils.getLogger());
230230
rcvs.L = Mockito.spy(rcvs.L);
231231
Assert.assertEquals(0, rcvs.getAllValues().size());
232232
Mockito.verify(rcvs.L, Mockito.times(2)).e(Mockito.anyString());

0 commit comments

Comments
 (0)