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
@IgnoreExtraProperties | |
public class BookObject extends ArrayList<BookObject> { | |
public String title; | |
public String subtitle; | |
public String authors; | |
public String imageURL; | |
private String pushId; | |
public BookObject(){} |
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
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; |
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
/** | |
* 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); |
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
/** | |
* 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 { |
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
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 |
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
// 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()); |
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
@Test | |
public void customComponentTest() throws Exception { | |
CountingIdlingResource componentIdlingResource = testedComponent.getIdlingResourceInTest(); | |
Espresso.registerIdlingResources(componentIdlingResource); | |
//perform checks for the specific component below | |
} |
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
@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()); | |
} |
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
@Module | |
public class RegistrationModule { | |
@ActivityScoped | |
@Provides | |
public RegistrationPresenter provideRegPresenter(RegistrationPresenter presenter) { | |
return presenter; | |
} | |
} |
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
@Module | |
public abstract class RegistrationModule { | |
@ActivityScoped | |
@Binds | |
public abstract RegistrationPresenter provideRegPresenter (RegistrationPresenter presenter); | |
} |
OlderNewer