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