Skip to content

Instantly share code, notes, and snippets.

@lvsecoto
Created February 12, 2019 02:13
Show Gist options
  • Save lvsecoto/a68b5feecf1f5e7eba418311009338cd to your computer and use it in GitHub Desktop.
Save lvsecoto/a68b5feecf1f5e7eba418311009338cd to your computer and use it in GitHub Desktop.
private static LifecycleOwner mockLifecycleOwner() {
LifecycleOwner owner = mock(LifecycleOwner.class);
LifecycleRegistry lifecycle = new LifecycleRegistry(owner);
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
when(owner.getLifecycle()).thenReturn(lifecycle);
return owner;
}
@SuppressWarnings("unchecked")
private static <T> Observer<T> mockObserver() {
return (Observer<T>) Mockito.mock(Observer.class);
}
@Rule
public TestRule rule = new InstantTaskExecutorRule();
// LiveData Test
dependencies {
// Test helpers for LiveData
androidTestImplementation "android.arch.core:core-testing:$lifecycle_version"
}
// Mockito
dependencies {
def mockito_version = "2.23.4"
testImplementation "org.mockito:mockito-core:$mockito_version"
androidTestImplementation "org.mockito:mockito-android:$mockito_version"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment