use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.
the class MemoryGaugeCollectorTest method setUp.
@Before
public void setUp() {
initMocks(this);
mockMemory();
fakeScheduledExecutorService = new FakeScheduledExecutorService();
testGaugeCollector = new MemoryGaugeCollector(fakeScheduledExecutorService, runtime);
}
use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.
the class DeviceCacheManagerTest method setUp.
@Before
public void setUp() {
fakeScheduledExecutorService = new FakeScheduledExecutorService();
deviceCacheManager = new DeviceCacheManager(fakeScheduledExecutorService);
}
use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.
the class AppStartTraceTest method testStartFromBackground.
@Test
public void testStartFromBackground() {
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
AppStartTrace trace = new AppStartTrace(transportManager, clock, fakeExecutorService);
trace.setIsStartFromBackground();
trace.onActivityCreated(activity1, bundle);
Assert.assertNull(trace.getOnCreateTime());
++currentTime;
trace.onActivityStarted(activity1);
Assert.assertNull(trace.getOnStartTime());
++currentTime;
trace.onActivityResumed(activity1);
Assert.assertNull(trace.getOnResumeTime());
// There should be no trace sent.
verify(transportManager, times(0)).log(traceArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
}
use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.
the class AppStartTraceTest method testInterleavedActivity.
/**
* Test second activity kicking in before the first activity onResume(). Second activity has no
* effect on AppStartTrace object.
*/
@Test
public void testInterleavedActivity() {
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
AppStartTrace trace = new AppStartTrace(transportManager, clock, fakeExecutorService);
// first activity onCreate()
currentTime = 1;
trace.onActivityCreated(activity1, bundle);
Assert.assertEquals(activity1, trace.getLaunchActivity());
Assert.assertEquals(1, trace.getOnCreateTime().getMicros());
// second activity onCreate(), should not change onCreate time.
currentTime = 2;
trace.onActivityCreated(activity2, bundle);
Assert.assertEquals(1, trace.getOnCreateTime().getMicros());
// second activity onStart() time is recorded as onStartTime.
currentTime = 3;
trace.onActivityStarted(activity2);
Assert.assertEquals(3, trace.getOnStartTime().getMicros());
// second activity onResume() time is recorded as onResumeTime.
// and second activity is recorded as AppStartActivity.
currentTime = 4;
trace.onActivityResumed(activity2);
Assert.assertEquals(activity1, trace.getLaunchActivity());
Assert.assertEquals(activity2, trace.getAppStartActivity());
fakeExecutorService.runAll();
verifyFinalState(activity2, trace, 1, 3, 4);
// first activity continues.
currentTime = 5;
trace.onActivityStarted(activity1);
currentTime = 6;
trace.onActivityResumed(activity1);
fakeExecutorService.runAll();
verifyFinalState(activity2, trace, 1, 3, 4);
}
use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.
the class AppStartTraceTest method testLaunchActivity.
/**
* Test activity sequentially goes through onCreate()->onStart()->onResume() state change.
*/
@Test
public void testLaunchActivity() {
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
AppStartTrace trace = new AppStartTrace(transportManager, clock, fakeExecutorService);
// first activity goes through onCreate()->onStart()->onResume() state change.
currentTime = 1;
trace.onActivityCreated(activity1, bundle);
currentTime = 2;
trace.onActivityStarted(activity1);
currentTime = 3;
trace.onActivityResumed(activity1);
fakeExecutorService.runAll();
verifyFinalState(activity1, trace, 1, 2, 3);
// same activity goes through onCreate()->onStart()->onResume() state change again.
// should have no effect on AppStartTrace.
currentTime = 4;
trace.onActivityCreated(activity1, bundle);
currentTime = 5;
trace.onActivityStarted(activity1);
currentTime = 6;
trace.onActivityResumed(activity1);
fakeExecutorService.runAll();
verifyFinalState(activity1, trace, 1, 2, 3);
// a different activity goes through onCreate()->onStart()->onResume() state change.
// should have no effect on AppStartTrace.
currentTime = 7;
trace.onActivityCreated(activity2, bundle);
currentTime = 8;
trace.onActivityStarted(activity2);
currentTime = 9;
trace.onActivityResumed(activity2);
fakeExecutorService.runAll();
verifyFinalState(activity1, trace, 1, 2, 3);
}
Aggregations