Skip to content

Instantly share code, notes, and snippets.

View catalinghita8's full-sized avatar

Catalin Ghita catalinghita8

View GitHub Profile
@IgnoreExtraProperties
public class BookObject extends ArrayList<BookObject> {
public String title;
public String subtitle;
public String authors;
public String imageURL;
private String pushId;
public BookObject(){}
public class CatalogAdapter extends ArrayAdapter<BookObject> {
public CatalogAdapter(Activity context, List<BookObject> books) {
super(context, 0, books); // 2nd par is 0 because we inflate manually
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if the existing view is being reused, otherwise inflate the view
View listItemView = convertView;
/**
* Contains a static reference IdlingResource, and should be available only in a mock build type.
*/
public class EspressoIdlingResource {
private static final String RESOURCE = "GLOBAL";
private static SimpleCountingIdlingResource mCountingIdlingResource =
new SimpleCountingIdlingResource(RESOURCE);
/**
* An simple counter implementation of that determines idleness by
* maintaining an internal counter. When the counter is 0 - it is considered to be idle, when it is
* non-zero it is not idle. This is very similar to the way a Semaphore
* behaves.
* This class can then be used to wrap up operations that while in progress should block tests from
* accessing the UI.
*/
public final class SimpleCountingIdlingResource implements IdlingResource {
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
// 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());
@Test
public void customComponentTest() throws Exception {
CountingIdlingResource componentIdlingResource = testedComponent.getIdlingResourceInTest();
Espresso.registerIdlingResources(componentIdlingResource);
//perform checks for the specific component below
}
@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());
}
@Module
public class RegistrationModule {
@ActivityScoped
@Provides
public RegistrationPresenter provideRegPresenter(RegistrationPresenter presenter) {
return presenter;
}
}
@Module
public abstract class RegistrationModule {
@ActivityScoped
@Binds
public abstract RegistrationPresenter provideRegPresenter (RegistrationPresenter presenter);
}