Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sdk-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ dependencies {
implementation 'org.json:json:20250107'
implementation 'com.google.code.findbugs:jsr305:3.0.2'

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@RunWith(JUnit4.class)
public class EventImplTests {

Log L = mock(Log.class);
Log L = TestUtils.getLogger();

/**
* Constructor of EventImpl class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
import static ly.count.sdk.java.internal.SDKStorage.FILE_NAME_SEPARATOR;
import static ly.count.sdk.java.internal.TestUtils.validateEvent;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

@RunWith(JUnit4.class)
public class EventQueueTests {

Log L = mock(Log.class);
Log L = TestUtils.getLogger();

EventQueue eventQueue;

Expand Down Expand Up @@ -96,7 +95,7 @@ public void writeEventQueueToStorage() {
@Test
public void writeEventQueueToStorage_emptyCache() {
eventQueue = spy(EventQueue.class);
eventQueue.L = mock(Log.class);
eventQueue.L = TestUtils.getLogger();
eventQueue.eventQueueMemoryCache = new ArrayList<>();

eventQueue.writeEventQueueToStorage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@RunWith(JUnit4.class)
public class ImmediateRequestTest {
Log L = mock(Log.class);
Log L = TestUtils.getLogger();

@After
public void stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@RunWith(JUnit4.class)
public class JsonFileStorageTests {

private static final Log L = Mockito.mock(Log.class);
private static Log L = TestUtils.getLogger();
JsonFileStorage storage;
static final String JSON_FILE_NAME = "test.json";

Expand Down Expand Up @@ -78,6 +78,7 @@ public void readJsonFile_emptyJsonFile() {
@Test
public void readJsonFile_IOException() throws IOException {
File file = Mockito.mock(File.class);
L = Mockito.spy(L);
Mockito.doThrow(new IOException("Simulated IOException")).when(file).createNewFile();

storage = new JsonFileStorage(file, L);
Expand Down
18 changes: 1 addition & 17 deletions sdk-java/src/test/java/ly/count/sdk/java/internal/LogTests.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
package ly.count.sdk.java.internal;

import ly.count.sdk.java.Config;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.powermock.reflect.Whitebox;

import ly.count.sdk.java.Config;

import static ly.count.sdk.java.Config.LoggingLevel.DEBUG;
import static ly.count.sdk.java.Config.LoggingLevel.ERROR;
import static ly.count.sdk.java.Config.LoggingLevel.INFO;
import static ly.count.sdk.java.Config.LoggingLevel.OFF;
import static ly.count.sdk.java.Config.LoggingLevel.WARN;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(JUnit4.class)
public class LogTests {
private static final String message = "message";
private static final Throwable exception = new IllegalStateException("IAS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void beforeTest() {
*/
private void initStorage() {
InternalConfig config = (new InternalConfig(TestUtils.getBaseConfig()));
config.setLogger(mock(Log.class));
config.setLogger(TestUtils.getLogger());
storageProvider = new SDKStorage().init(config);
}

Expand All @@ -90,7 +90,7 @@ public void afterTest() {
*/
@Test
public void migrationHelper_defaults() {
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
Assert.assertEquals(-1, migrationHelper.currentDataModelVersion);//validate the default version value
Assert.assertNotNull(migrationHelper.logger);
Assert.assertNull(migrationHelper.storageProvider);
Expand All @@ -105,7 +105,7 @@ public void migrationHelper_defaults() {
@Test
public void setupMigrations_freshInstall() {
initStorage(); // to initialize json storage
MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
migrationHelper.setupMigrations(storageProvider);
Assert.assertEquals(expectedLatestSchemaVersion, migrationHelper.currentDataModelVersion);
}
Expand All @@ -120,7 +120,7 @@ public void setupMigrations_legacyState() {
TestUtils.createFile("test"); //mock a sdk file, to simulate storage is not empty
initStorage(); // to initialize json storage after mock sdk file is created

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

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

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

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

MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
migrationHelper.setupMigrations(storageProvider);
Assert.assertEquals(0, migrationHelper.currentDataModelVersion); //legacy state

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

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

MigrationHelper migrationHelper = new MigrationHelper(mock(Log.class));
MigrationHelper migrationHelper = new MigrationHelper(TestUtils.getLogger());
migrationHelper.setupMigrations(storageProvider);
Assert.assertEquals(1, migrationHelper.currentDataModelVersion);
migrationHelper.logger = Mockito.spy(migrationHelper.logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@RunWith(JUnit4.class)
public class ModuleFeedbackTests {

Log L = mock(Log.class);
Log L = TestUtils.getLogger();

@Before
public void beforeTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void multiThread() throws BrokenBarrierException, InterruptedException {
}

gate.await();
Storage.await(Mockito.mock(Log.class));
Storage.await(TestUtils.getLogger());

for (Thread t : runs) {
t.join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class RemoteConfigValueStoreTests {
*/
@Test
public void constructor_defaults() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(new JSONObject(), false, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(new JSONObject(), false, TestUtils.getLogger());
Assert.assertEquals(RemoteConfigValueStore.keyValue, "v");
Assert.assertEquals(RemoteConfigValueStore.keyCacheFlag, "c");
Assert.assertEquals(RemoteConfigValueStore.cacheValCached, 0);
Expand All @@ -35,7 +35,7 @@ public void constructor_defaults() {
*/
@Test
public void cacheClearValues_cachingDisabled() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), false, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), false, TestUtils.getLogger());
Assert.assertEquals(2, rcvs.getAllValues().size());
rcvs.cacheClearValues();
Assert.assertEquals(rcvs.values.length(), 0);
Expand All @@ -48,7 +48,7 @@ public void cacheClearValues_cachingDisabled() {
*/
@Test(expected = NullPointerException.class)
public void cacheClearValues_nullRcValues() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, false, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, false, TestUtils.getLogger());
rcvs.cacheClearValues();
}

Expand All @@ -59,7 +59,7 @@ public void cacheClearValues_nullRcValues() {
*/
@Test
public void cacheClearValues_cachingEnabled() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
Assert.assertEquals(2, rcvs.getAllValues().size());
rcvs.cacheClearValues();
Assert.assertEquals(2, rcvs.getAllValues().size());
Expand All @@ -74,7 +74,7 @@ public void cacheClearValues_cachingEnabled() {
*/
@Test
public void cacheClearValues_garbageJson() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, TestUtils.getLogger());
rcvs.L = Mockito.spy(rcvs.L);
rcvs.cacheClearValues();
Mockito.verify(rcvs.L, Mockito.times(1)).w("[RemoteConfigValueStore] cacheClearValues, stored entry was not a JSON object, key:[" + TestUtils.keysValues[0] + "] value:[garbage]");
Expand All @@ -89,7 +89,7 @@ public void cacheClearValues_garbageJson() {
*/
@Test
public void mergeValues_fullUpdate() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
Assert.assertEquals(2, rcvs.getAllValues().size());
Assert.assertEquals(TestUtils.keysValues[1], rcvs.getValue(TestUtils.keysValues[0]).value);
rcvs.mergeValues(newRCValues(), true);
Expand All @@ -105,7 +105,7 @@ public void mergeValues_fullUpdate() {
*/
@Test
public void mergeValues_notFullUpdate() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
Assert.assertEquals(2, rcvs.getAllValues().size());
Assert.assertEquals(TestUtils.keysValues[1], rcvs.getValue(TestUtils.keysValues[0]).value);
rcvs.mergeValues(newRCValues(), false);
Expand All @@ -121,7 +121,7 @@ public void mergeValues_notFullUpdate() {
*/
@Test(expected = NullPointerException.class)
public void mergeValues_nullNewRcValues() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
Assert.assertEquals(2, rcvs.getAllValues().size());
rcvs.mergeValues(null, false);
}
Expand All @@ -133,7 +133,7 @@ public void mergeValues_nullNewRcValues() {
*/
@Test(expected = NullPointerException.class)
public void mergeValues_nullRcValues() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, TestUtils.getLogger());
rcvs.mergeValues(newRCValues(), false);
}

Expand All @@ -144,7 +144,7 @@ public void mergeValues_nullRcValues() {
*/
@Test
public void getValue_nullRcValues() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, TestUtils.getLogger());
rcvs.L = Mockito.spy(rcvs.L);
Assert.assertNull(rcvs.getValue(TestUtils.keysValues[0]).value);
Mockito.verify(rcvs.L, Mockito.times(1)).e(Mockito.anyString());
Expand All @@ -157,7 +157,7 @@ public void getValue_nullRcValues() {
*/
@Test
public void getValue() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
Assert.assertEquals(TestUtils.keysValues[1], rcvs.getValue(TestUtils.keysValues[0]).value);
}

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

Expand All @@ -179,7 +179,7 @@ public void getValue_notExist() {
*/
@Test
public void getValue_garbageJson() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, TestUtils.getLogger());
Assert.assertEquals(1, rcvs.values.length());
Assert.assertNull(rcvs.getValue(TestUtils.keysValues[0]).value);
}
Expand All @@ -191,7 +191,7 @@ public void getValue_garbageJson() {
*/
@Test
public void getAllValues() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson(RemoteConfigValueStore.keyCacheFlag), true, TestUtils.getLogger());
Assert.assertEquals(2, rcvs.getAllValues().size());
Assert.assertEquals(2, rcvs.values.length());
}
Expand All @@ -203,7 +203,7 @@ public void getAllValues() {
*/
@Test(expected = NullPointerException.class)
public void getAllValues_nullRcValues() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(null, true, TestUtils.getLogger());
rcvs.getAllValues();
}

Expand All @@ -214,7 +214,7 @@ public void getAllValues_nullRcValues() {
*/
@Test
public void getAllValues_garbageJson() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(garbageJson(), true, TestUtils.getLogger());
Assert.assertEquals(0, rcvs.getAllValues().size());
Assert.assertEquals(1, rcvs.values.length());
}
Expand All @@ -226,7 +226,7 @@ public void getAllValues_garbageJson() {
*/
@Test
public void getAllValues_garbageCacheKey() {
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson("garbage"), true, Mockito.mock(Log.class));
RemoteConfigValueStore rcvs = new RemoteConfigValueStore(rcvsJson("garbage"), true, TestUtils.getLogger());
rcvs.L = Mockito.spy(rcvs.L);
Assert.assertEquals(0, rcvs.getAllValues().size());
Mockito.verify(rcvs.L, Mockito.times(2)).e(Mockito.anyString());
Expand Down
Loading
Loading