Created
February 1, 2017 01:11
-
-
Save ecgreb/236bd6150480a2299db754b097e14fa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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