Skip to content

Instantly share code, notes, and snippets.

View catalinghita8's full-sized avatar

Catalin Ghita catalinghita8

View GitHub Profile
public class MessageActivity extends DaggerAppCompatActivity {
@Inject
MessageFragment mInjectedFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
// Set up fragment
android {
...
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
@Module(includes = ServletRequestAbstractModule.class)
final class ServletRequestModule {
private final HttpServletRequest httpRequest;
@Provides
HttpServletRequestModule(HttpServletRequest httpRequest) {
this.httpRequest = httpRequest;
}
@Module
@Module
public abstract class RegistrationModule {
@ActivityScoped
@Binds
public abstract RegistrationPresenter provideRegPresenter (RegistrationPresenter presenter);
@ActivityScoped
@Provides
static String provideActivityId(RegistrationActivity activity) {
return activity.getIntent().getStringExtra(ID);
@Module
public abstract class RegistrationModule {
@ActivityScoped
@Binds
public abstract RegistrationPresenter provideRegPresenter (RegistrationPresenter presenter);
}
@Module
public class RegistrationModule {
@ActivityScoped
@Provides
public RegistrationPresenter provideRegPresenter(RegistrationPresenter presenter) {
return presenter;
}
}
@Test
public void contentTest() {
// quick check if the ListView is visible
onView(withId(R.id.list)).check(matches(isDisplayed()));
// click on a certain child view from the loaded list
onData(allOf()).inAdapterView(withId(R.id.list_news)).atPosition(i)
.perform(click());
}
@Test
public void customComponentTest() throws Exception {
CountingIdlingResource componentIdlingResource = testedComponent.getIdlingResourceInTest();
Espresso.registerIdlingResources(componentIdlingResource);
//perform checks for the specific component below
}
// Register your Idling Resource before any tests regarding this component
@Before
public void registerIdlingResource() {
IdlingRegistry.getInstance().register(EspressoIdlingResource.getIdlingResource());
}
// Unregister your Idling Resource so it can be garbage collected and does not leak any memory
@After
public void unregisterIdlingResource() {
IdlingRegistry.getInstance().unregister(EspressoIdlingResource.getIdlingResource());
public void loadData() {
// The network request might be handled in a different thread so make sure Espresso knows
// that the app is busy until the response is handled.
EspressoIdlingResource.increment(); // App is busy until further notice
// let's get the data
mRepository.getData(new LoadDataCallback() {
@Override
public void onDataLoaded(Data data) {
// now that the data has been loaded, we can mark the app as idle