From 62617581a2de4b4778724caa22b22388b62a60d3 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:21:04 +0300 Subject: [PATCH] [Java] rework crash reporting tests (#100) * feat: control from rq * fix: remoove sout line * feat: increase timer * fix: git action try * fix: git actiooons * fix: git action * fix: undo git actions * fix: wait for oobject not sleep * chore: remove comment --- .../sdk/java/internal/SessionImplTests.java | 84 ++++++++----------- .../sdk/java/internal/TimedEventsTests.java | 4 +- 2 files changed, 39 insertions(+), 49 deletions(-) diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java index 4a3356ab7..93cbd22f9 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java @@ -2,10 +2,8 @@ import java.util.List; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import java.util.function.BiFunction; import java.util.function.Consumer; -import java.util.function.Function; import ly.count.sdk.java.Config; import ly.count.sdk.java.Countly; import ly.count.sdk.java.Session; @@ -16,13 +14,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.verification.VerificationMode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -442,49 +436,43 @@ private void addLocation_base(Config config, Object expected) { Assert.assertEquals(expected, session.params.get("location")); } + + /** + * "addCrashReport" with no consent to crash reporting + * mocked exception given to function and validating function calls + * SDKCore.instance().onCrash() should not be called + */ + @Test + public void addCrashReport_crashReportingNotEnabled() { + addCrashReport_base(TestUtils.getConfigSessions(), 0); + } + + /** + * "addCrashReport" + * mocked exception given to function and validating function calls + * SDKCore.instance().onCrash() should be called once + */ + @Test + public void addCrashReport() { + addCrashReport_base(TestUtils.getConfigSessions(Config.Feature.CrashReporting), 1); + } - //todo long spy issue - ///** - // * "addCrashReport" with no consent to crash reporting - // * mocked exception given to function and validating function calls - // * SDKCore.instance().onCrash() should not be called - // */ - //@Test - //public void addCrashReport_crashReportingNotEnabled() { - // addCrashReport_base(TestUtils.getConfigSessions(), never()); - //} - // - ///** - // * "addCrashReport" - // * mocked exception given to function and validating function calls - // * SDKCore.instance().onCrash() should be called once - // */ - //@Test - //public void addCrashReport() { - // addCrashReport_base(TestUtils.getConfigSessions(Config.Feature.CrashReporting), times(1)); - //} - // - ///** - // * "addCrashReport" with backend mode enabled - // * mocked exception given to function and validating function calls - // * SDKCore.instance().onCrash() should not be called and expected log should be logged - // */ - //@Test - //public void addCrashReport_backendModeEnabled() { - // SessionImpl session = addCrashReport_base(TestUtils.getConfigSessions().enableBackendMode(), never()); - // verify(session.L, times(1)).w("[SessionImpl] addCrashReport: Skipping crash, backend mode is enabled!"); - //} - // - //private SessionImpl addCrashReport_base(Config config, VerificationMode verificationMode) { - // Countly.instance().init(config); - // SessionImpl session = (SessionImpl) Countly.session(); - // //SDKCore.instance = spy(SDKCore.instance); - // //session.L = spy(session.L); - // session.addCrashReport(new Exception(), false); - // - // verify(SDKCore.instance, verificationMode).onCrash(any(), any(), anyBoolean(), any(), any(), any()); - // return session; - //} + /** + * "addCrashReport" with backend mode enabled + * mocked exception given to function and validating function calls + * SDKCore.instance().onCrash() should not be called and expected log should be logged + */ + @Test + public void addCrashReport_backendModeEnabled() { + addCrashReport_base(TestUtils.getConfigSessions().enableBackendMode(), 0); + } + + private void addCrashReport_base(Config config, int rqSize) { + Countly.instance().init(config); + SessionImpl session = (SessionImpl) Countly.session(); + session.addCrashReport(new Exception(), false); + Assert.assertEquals(rqSize, TestUtils.getCurrentRQ().length); + } /** * "hashCode" diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/TimedEventsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/TimedEventsTests.java index 285af8480..baf232cef 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/TimedEventsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/TimedEventsTests.java @@ -61,7 +61,9 @@ public void recordEventRegularFlow_base(boolean regularRecord) throws Interrupte TestUtils.validateEQSize(0); - Thread.sleep(1000); + synchronized (tEvent) { + tEvent.wait(1000); + } double targetDuration; if (regularRecord) {