ScreenTrackingEvent extends Event { @Override public boolean isValid() { if (screen.length() > SCREEN_TRACKING_EVENT_MAX_CHARACTERS || screen.length() <= 0) { Logger.error("Screen identifier string must be between 1 and 255 characters long."); return false; } if (startTime > stopTime) { Logger.error("Screen tracking duration must be positive or zero."); return false; } return true; } ScreenTrackingEvent(@NonNull String screen, @Nullable String previousScreen, long startTime, long stopTime); @Override boolean isValid(); @NonNull @Override String getType(); @NonNull @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) final JsonMap getEventData();  }
@Test public void testSetScreen() throws JSONException { String screen = createFixedSizeString('a', 256); ScreenTrackingEvent event = new ScreenTrackingEvent(screen, null, 0, 1); Assert.assertFalse(event.isValid()); screen = createFixedSizeString('a', 255); event = new ScreenTrackingEvent(screen, null, 0, 1); Assert.assertTrue(event.isValid()); screen = ""; event = new ScreenTrackingEvent(screen, null, 0, 1); Assert.assertFalse(event.isValid()); }
@Test public void testSetDuration() throws JSONException { ScreenTrackingEvent event = new ScreenTrackingEvent("test_screen", null, 0, 1); Assert.assertTrue(event.isValid()); event = new ScreenTrackingEvent("test_screen", null, 0, 0); Assert.assertTrue(event.isValid()); event = new ScreenTrackingEvent("test_screen", null, 0, -1); Assert.assertFalse(event.isValid()); }