• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.server.location;
2 
3 import static com.google.common.truth.Truth.assertThat;
4 
5 import static org.mockito.ArgumentMatchers.anyBoolean;
6 import static org.mockito.ArgumentMatchers.anyLong;
7 import static org.mockito.ArgumentMatchers.eq;
8 import static org.mockito.Mockito.times;
9 import static org.mockito.Mockito.verify;
10 import static org.mockito.Mockito.when;
11 
12 import android.platform.test.annotations.Presubmit;
13 
14 import com.android.server.location.GnssBatchingProvider.GnssBatchingProviderNative;
15 
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.robolectric.RobolectricTestRunner;
22 
23 /**
24  * Unit tests for {@link GnssBatchingProvider}.
25  */
26 @RunWith(RobolectricTestRunner.class)
27 @Presubmit
28 public class GnssBatchingProviderTest {
29 
30     private static final long PERIOD_NANOS = (long) 1e9;
31     private static final boolean WAKE_ON_FIFO_FULL = true;
32     private static final int BATCH_SIZE = 3;
33     @Mock
34     private GnssBatchingProviderNative mMockNative;
35     private GnssBatchingProvider mTestProvider;
36 
37     @Before
setUp()38     public void setUp() {
39         MockitoAnnotations.initMocks(this);
40         when(mMockNative.initBatching()).thenReturn(true);
41         when(mMockNative.startBatch(anyLong(), anyBoolean())).thenReturn(true);
42         when(mMockNative.stopBatch()).thenReturn(true);
43         when(mMockNative.getBatchSize()).thenReturn(BATCH_SIZE);
44         mTestProvider = new GnssBatchingProvider(mMockNative);
45         mTestProvider.enable();
46         mTestProvider.start(PERIOD_NANOS, WAKE_ON_FIFO_FULL);
47     }
48 
49     @Test
start_nativeStarted()50     public void start_nativeStarted() {
51         verify(mMockNative).startBatch(eq(PERIOD_NANOS), eq(WAKE_ON_FIFO_FULL));
52     }
53 
54     @Test
stop_nativeStopped()55     public void stop_nativeStopped() {
56         mTestProvider.stop();
57         verify(mMockNative).stopBatch();
58     }
59 
60     @Test
flush_nativeFlushed()61     public void flush_nativeFlushed() {
62         mTestProvider.flush();
63         verify(mMockNative).flushBatch();
64     }
65 
66     @Test
getBatchSize_nativeGetBatchSize()67     public void getBatchSize_nativeGetBatchSize() {
68         assertThat(mTestProvider.getBatchSize()).isEqualTo(BATCH_SIZE);
69     }
70 
71     @Test
started_resume_started()72     public void started_resume_started() {
73         mTestProvider.resumeIfStarted();
74         verify(mMockNative, times(2)).startBatch(eq(PERIOD_NANOS), eq(WAKE_ON_FIFO_FULL));
75     }
76 
77     @Test
stopped_resume_notStarted()78     public void stopped_resume_notStarted() {
79         mTestProvider.stop();
80         mTestProvider.resumeIfStarted();
81         verify(mMockNative, times(1)).startBatch(eq(PERIOD_NANOS), eq(WAKE_ON_FIFO_FULL));
82     }
83 }
84