Skip to content

Instantly share code, notes, and snippets.

View ecgreb's full-sized avatar

Chuck Greb ecgreb

View GitHub Profile
dependencies:
pre:
- echo y | android update sdk --all --no-ui --filter "build-tools-25.0.2"
- echo y | android update sdk --all --no-ui --filter "android-25"
- echo y | android update sdk --all --no-ui --filter "extra-android-m2repository"
<resources>
<string name="success_title">Success</string>
<string name="success_description">Congrats you did it!</string>
<string name="error_title">Error</string>
<string name="error_description">Uh oh something went wrong</string>
</resources>
public class ResourceManagerTest {
private TestResources resources = new TestResources();
private ResourceManager resourceManager = new ResourceManager(resources);
@Test public void shouldNotBeNull() throws Exception {
assertThat(resourceManager).isNotNull();
}
@Test public void getTitle_true_shouldReturnSuccessTitle() throws Exception {
assertThat(resourceManager.getTitle(true)).isEqualTo("Success");
public class ResourceManager {
private Resources resources;
public ResourceManager(Resources resources) {
this.resources = resources;
}
public String getTitle(boolean success) {
if (success) {
return resources.getString(R.string.success_title);
@RunWith(PowerMockRunner.class)
@PrepareForTest(ContextCompat.class)
@PowerMockIgnore("javax.net.ssl.*")
public class UserLocationStoreTest {
private UserLocationStore userLocationStore;
@Before public void setUp() throws Exception {
userLocationStore = new UserLocationStore(PowerMockito.mock(Context.class));
}
public static void initMockSslContext() throws KeyStoreException, NoSuchAlgorithmException {
final TrustManagerFactory trustManagerFactory = PowerMockito.mock(TrustManagerFactory.class);
final TrustManager[] trustManagers = new TrustManager[1];
// Mock TrustManagerFactory.getInstance(String)
mockStatic(TrustManagerFactory.class);
when(TrustManagerFactory.getInstance(anyString())).thenReturn(trustManagerFactory);
// Mock TrustManagerFactory#getTrustManagers()
trustManagers[0] = PowerMockito.mock(X509TrustManager.class);
@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 {
public class UserLocationStore {
private final Context context;
public UserLocationStore(Context context) {
this.context = context;
}
public UserLocation getLocation() {
if (ContextCompat.checkSelfPermission(context,
Manifest.permission.ACCESS_FINE_LOCATION)
java.lang.AssertionError
at okhttp3.OkHttpClient.systemDefaultTrustManager(OkHttpClient.java:275)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:242)
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:878)
at com.example.ecgreb.mvpc.model.NetworkClient.<init>(NetworkClient.java:16)
at com.example.ecgreb.mvpc.model.NetworkClientTest.setUp(NetworkClientTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
public class MapViewTest {
// ...
@Test public void shouldInflateLayoutWithOverlayModeSdk() throws Exception {
Context context = mock(Context.class);
TypedArray typedArray = mock(TypedArray.class);
TestLayoutInflater layoutInflater = new TestLayoutInflater(context);
initMockAttributes(context, typedArray, layoutInflater, OVERLAY_MODE_SDK);