Skip to content

Instantly share code, notes, and snippets.

@ecgreb
Created February 1, 2017 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecgreb/236bd6150480a2299db754b097e14fa5 to your computer and use it in GitHub Desktop.
Save ecgreb/236bd6150480a2299db754b097e14fa5 to your computer and use it in GitHub Desktop.
@RunWith(PowerMockRunner.class)
@PrepareForTest(ContextCompat.class)
public class UserLocationStoreTest {
private UserLocationStore userLocationStore;
@Before public void setUp() throws Exception {
userLocationStore = new UserLocationStore(PowerMockito.mock(Context.class));
}
@Test public void getLocation_shouldReturnDeviceLocation() throws Exception {
PowerMockito.mockStatic(ContextCompat.class);
PowerMockito.when(ContextCompat.checkSelfPermission(any(Context.class), anyString()))
.thenReturn(PackageManager.PERMISSION_GRANTED);
assertThat(userLocationStore.getLocation().getSource()).isEqualTo("device");
}
@Test public void getLocation_shouldReturnWebLocation() throws Exception {
PowerMockito.mockStatic(ContextCompat.class);
PowerMockito.when(ContextCompat.checkSelfPermission(any(Context.class), anyString()))
.thenReturn(PackageManager.PERMISSION_DENIED);
assertThat(userLocationStore.getLocation().getSource()).isEqualTo("web");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment