Search in sources :

Example 16 with Timer

use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.

the class TraceMetricBuilderTest method setUp.

@Before
public void setUp() {
    currentTime = 0;
    initMocks(this);
    doAnswer(new Answer<Timer>() {

        @Override
        public Timer answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new Timer(currentTime);
        }
    }).when(clock).getTime();
}
Also used : Timer(com.google.firebase.perf.util.Timer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Example 17 with Timer

use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.

the class AppStartTraceTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    doAnswer(new Answer<Timer>() {

        @Override
        public Timer answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new Timer(currentTime);
        }
    }).when(clock).getTime();
    transportManager = mock(TransportManager.class);
    traceArgumentCaptor = ArgumentCaptor.forClass(TraceMetric.class);
    appStartTime = FirebasePerfProvider.getAppStartTime().getMicros();
    appStartHRT = FirebasePerfProvider.getAppStartTime().getHighResTime();
}
Also used : Timer(com.google.firebase.perf.util.Timer) TraceMetric(com.google.firebase.perf.v1.TraceMetric) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TransportManager(com.google.firebase.perf.transport.TransportManager) Before(org.junit.Before)

Example 18 with Timer

use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.

the class FirebasePerfTraceValidatorTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    doAnswer(new Answer<Timer>() {

        @Override
        public Timer answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new Timer(currentTime);
        }
    }).when(clock).getTime();
}
Also used : Timer(com.google.firebase.perf.util.Timer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Example 19 with Timer

use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.

the class TraceTest method setUp.

@Before
public void setUp() {
    currentTime = 1;
    initMocks(this);
    doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(mockClock).getTime();
    arguments = ArgumentCaptor.forClass(TraceMetric.class);
    DeviceCacheManager.clearInstance();
    ConfigResolver.clearInstance();
    appContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().clear().commit();
    ConfigResolver configResolver = ConfigResolver.getInstance();
    configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
    configResolver.setApplicationContext(appContext);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Context(android.content.Context) TraceMetric(com.google.firebase.perf.v1.TraceMetric) ArgumentMatchers(org.mockito.ArgumentMatchers) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Random(java.util.Random) PREFS_NAME(com.google.firebase.perf.util.Constants.PREFS_NAME) Parcel(android.os.Parcel) AppStateMonitor(com.google.firebase.perf.application.AppStateMonitor) Answer(org.mockito.stubbing.Answer) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) Constants(com.google.firebase.perf.util.Constants) ArgumentCaptor(org.mockito.ArgumentCaptor) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) PerfSession(com.google.firebase.perf.session.PerfSession) FirebasePerformanceTestBase(com.google.firebase.perf.FirebasePerformanceTestBase) GaugeManager(com.google.firebase.perf.session.gauges.GaugeManager) ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Before(org.junit.Before) Timer(com.google.firebase.perf.util.Timer) Clock(com.google.firebase.perf.util.Clock) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) TransportManager(com.google.firebase.perf.transport.TransportManager) Mockito.verify(org.mockito.Mockito.verify) SessionManager(com.google.firebase.perf.session.SessionManager) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) Mockito.never(org.mockito.Mockito.never) Mockito.mock(org.mockito.Mockito.mock) ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Timer(com.google.firebase.perf.util.Timer) TraceMetric(com.google.firebase.perf.v1.TraceMetric) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) Before(org.junit.Before)

Example 20 with Timer

use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.

the class InstrumentOkHttpEnqueueCallbackTest method mockTimer.

private static Timer mockTimer() {
    Timer timer = mock(Timer.class);
    when(timer.getDurationMicros()).thenReturn((long) 2000);
    return timer;
}
Also used : Timer(com.google.firebase.perf.util.Timer)

Aggregations

Timer (com.google.firebase.perf.util.Timer)38 Test (org.junit.Test)29 Before (org.junit.Before)7 TransportManager (com.google.firebase.perf.transport.TransportManager)4 TraceMetric (com.google.firebase.perf.v1.TraceMetric)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)3 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)3 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)3 Clock (com.google.firebase.perf.util.Clock)3 Constants (com.google.firebase.perf.util.Constants)3 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)3 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)3 RunWith (org.junit.runner.RunWith)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 ArgumentMatchers.nullable (org.mockito.ArgumentMatchers.nullable)3 Mock (org.mockito.Mock)3 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 Mockito.mock (org.mockito.Mockito.mock)3