コード例 #1
0
  @Override
  protected void tearDown() throws Exception {
    super.tearDown();

    AdjustFactory.setPackageHandler(null);
    AdjustFactory.setLogger(null);
    AdjustFactory.setTimerInterval(-1);
    AdjustFactory.setSessionInterval(-1);
    AdjustFactory.setSubsessionInterval(-1);
  }
コード例 #2
0
  public void testDisable() {
    Context context = activity.getApplicationContext();

    // starting from a clean slate
    mockLogger.test(
        "Was AdjustActivityState deleted? " + ActivityHandler.deleteActivityState(context));

    // set the timer for a shorter time for testing
    AdjustFactory.setTimerInterval(700);

    ActivityHandler activityHandler =
        new ActivityHandler(activity, "qwerty123456", "sandbox", "verbose", false);

    // verify the default value, when not started
    assertTrue(activityHandler.isEnabled());

    activityHandler.setEnabled(false);

    // verify the default value, when not started
    assertFalse(activityHandler.isEnabled());

    // start the first session
    activityHandler.trackSubsessionStart();
    activityHandler.trackEvent("123456", null);
    activityHandler.trackRevenue(0.1, null, null);
    activityHandler.trackSubsessionEnd();
    activityHandler.trackSubsessionStart();

    SystemClock.sleep(1000);

    // verify the changed value after the activity handler is started
    assertFalse(activityHandler.isEnabled());

    // making sure the first session was sent
    assertTrue(mockLogger.toString(), mockLogger.containsMessage(LogLevel.INFO, "First session"));

    // delete the first session package from the log
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler sendFirstPackage"));

    // making sure the timer fired did not call the package handler
    assertFalse(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler sendFirstPackage"));

    // test if the event was not triggered
    assertFalse(mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Event 1"));
    // test if the revenue was not triggered
    assertFalse(
        mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Event 1 (revenue)"));

    // verify that the application was paused
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler pauseSending"));
    // verify that it was not resumed
    assertFalse(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler resumeSending"));

    // enable again
    activityHandler.setEnabled(true);

    SystemClock.sleep(1000);

    // verify that the timer was able to resume sending
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler resumeSending"));

    activityHandler.trackEvent("123456", null);
    activityHandler.trackRevenue(0.1, null, null);
    activityHandler.trackSubsessionEnd();
    activityHandler.trackSubsessionStart();
    SystemClock.sleep(1000);

    // verify the changed value, when the activity state is started
    assertTrue(activityHandler.isEnabled());

    // test that the event was triggered
    assertTrue(mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Event 1"));
    // test that the revenue was triggered
    assertTrue(
        mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Event 2 (revenue)"));

    // verify that the application was paused
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler pauseSending"));
    // verify that it was also resumed
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler resumeSending"));
    // */
  }