From a67ec2b4c0398e76555edbccc0286eb936303478 Mon Sep 17 00:00:00 2001 From: arifBurakDemiray Date: Tue, 10 Oct 2023 11:13:36 +0300 Subject: [PATCH] fix: delete moock spy test --- .../sdk/java/internal/MigrationHelper.java | 16 +++++--------- .../java/internal/MigrationHelperTests.java | 21 ------------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/MigrationHelper.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/MigrationHelper.java index 7a6fdd990..42ba8bcda 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/MigrationHelper.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/MigrationHelper.java @@ -21,7 +21,7 @@ */ public class MigrationHelper { protected static final String MIGRATION_VERSION_FILE_NAME = "migration_version"; - protected CtxCore ctx; + private CtxCore ctx; private final List> migrations; protected int appliedMigrationVersion = -1; protected Log logger; @@ -66,12 +66,12 @@ private void readMigrationVersion() { } } - protected void updateMigrationVersion() { + private void updateMigrationVersion() { logger.i("[MigrationHelper] updateMigrationVersion, Updating migration version to version:[ " + appliedMigrationVersion + " ]"); File file = new File(ctx.getSdkStorageRootDirectory(), SDKStorage.FILE_NAME_PREFIX + SDKStorage.FILE_NAME_SEPARATOR + MIGRATION_VERSION_FILE_NAME); - try { // Write the version to the file - writeVersionToFile(file); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { + writer.write(String.valueOf(appliedMigrationVersion)); logger.v("[MigrationHelper] writeFileContent, Wrote applied migration version to file"); } catch (IOException e) { // Handle the error if writing fails @@ -79,13 +79,7 @@ protected void updateMigrationVersion() { } } - protected void writeVersionToFile(File file) throws IOException { - try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { - writer.write(String.valueOf(appliedMigrationVersion)); - } - } - - protected boolean migration_DeleteConfigFile_00() { + private boolean migration_DeleteConfigFile_00() { if (appliedMigrationVersion >= 0) { logger.d("[MigrationHelper] migration_DeleteConfigFile_00, Migration already applied"); return true; diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java index 407e4a266..6b16726ba 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/MigrationHelperTests.java @@ -12,8 +12,6 @@ import static ly.count.sdk.java.internal.SDKStorage.FILE_NAME_PREFIX; import static ly.count.sdk.java.internal.SDKStorage.FILE_NAME_SEPARATOR; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; @@ -87,25 +85,6 @@ public void applyMigrations_migrationAlreadyApplied() { verify(migrationHelper.logger, times(1)).d("[MigrationHelper] migration_DeleteConfigFile_00, Migration already applied"); } - /** - * "updateMigrationVersion" with IO exception - * receives mock context and simulated function to throw IOException - * logger should log expected log - */ - @Test - public void updateMigrationVersion_IOException() throws IOException { - //prepare mock object - migrationHelper = spy(migrationHelper); - migrationHelper.ctx = TestUtils.getMockCtxCore(); - //simulate function to throw exception - doThrow(new IOException("Simulated IOException")).when(migrationHelper).writeVersionToFile(any(File.class)); - // Call the method that you want to test - migrationHelper.updateMigrationVersion(); - - // Verify that the logger's error method was called with the expected message - verify(migrationHelper.logger).e("[MigrationHelper] writeFileContent, Failed to write applied migration version to file: Simulated IOException"); - } - private void writeToMvFile(Integer version) { File file = new File(TestUtils.getTestSDirectory(), FILE_NAME_PREFIX + FILE_NAME_SEPARATOR + MigrationHelper.MIGRATION_VERSION_FILE_NAME); try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {