Navigation Menu

Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Sample tests #39

Merged
merged 26 commits into from Feb 24, 2016
Merged

Sample tests #39

merged 26 commits into from Feb 24, 2016

Conversation

flipper83
Copy link
Member

  • adding test to sample
  • adding error handler sample.

@flipper83
Copy link
Member Author

Thank you @pedrovgs for all support for this PR could be posible

startActivity();
onView(withId(R.id.rv_comics)).perform(RecyclerViewActions.scrollToPosition(1));

RecyclerViewInteraction.<ComicSeriesDetailViewModel>onRecyclerView(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a style issue but I'd move the recycler view check to a private method in order to make the test easier to read

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all right!!!

@Serchinastico
Copy link
Contributor

Good shit right there 👍, I include a patch with some typos corrected:

diff --git a/sample/src/androidTest/java/com/karumi/rosie/sample/comics/view/activity/ComicSeriesDetailsActivityTest.java b/sample/src/androidTest/java/com/karumi/rosie/sample/comics/view/activity/ComicSeriesDetailsActivityTest.java
index ba23a7c..26c0a65 100644
--- a/sample/src/androidTest/java/com/karumi/rosie/sample/comics/view/activity/ComicSeriesDetailsActivityTest.java
+++ b/sample/src/androidTest/java/com/karumi/rosie/sample/comics/view/activity/ComicSeriesDetailsActivityTest.java
@@ -60,7 +60,7 @@ import static org.mockito.Mockito.when;

 public class ComicSeriesDetailsActivityTest extends InjectedInstrumentationTest {

-  private static final int ANY_COMIC_SERIE_ID = 1;
+  private static final int ANY_COMIC_SERIES_ID = 1;
   private static final String ANY_EXCEPTION = "AnyException";
   @Rule public IntentsTestRule<ComicSeriesDetailsActivity> activityRule =
       new IntentsTestRule<>(ComicSeriesDetailsActivity.class, true, false);
@@ -68,7 +68,7 @@ public class ComicSeriesDetailsActivityTest extends InjectedInstrumentationTest
   @Inject
   ComicSeriesRepository comicSeriesRepository;

-  @Test public void shouldShowComicSeriesDetailWhenComicSerieIsLoaded() throws Exception {
+  @Test public void shouldShowComicSeriesDetailWhenComicSeriesIsLoaded() throws Exception {
     ComicSeries comicSeries = givenValidComicSeries();

     startActivity();
@@ -77,7 +77,7 @@ public class ComicSeriesDetailsActivityTest extends InjectedInstrumentationTest
     onView(withId(R.id.tv_description)).check(matches(withText(comicSeries.getDescription())));
   }

-  @Test public void shouldShowComicIfComicSerieHaveComics() throws Exception {
+  @Test public void shouldShowComicIfComicSeriesHaveComics() throws Exception {
     ComicSeries comicSeries = givenValidComicSeries();
     List<ComicSeriesDetailViewModel> comics = givenComicData(comicSeries);

@@ -105,7 +105,7 @@ public class ComicSeriesDetailsActivityTest extends InjectedInstrumentationTest
     onView((withId(R.id.loading))).check(matches(not(isDisplayed())));
   }

-  @Test public void shouldShowsErrorIfSomethingWrongHappend() throws Exception {
+  @Test public void shouldShowErrorIfSomethingWrongHappens() throws Exception {
     givenExceptionObtainingComicSeries();

     startActivity();
@@ -114,7 +114,7 @@ public class ComicSeriesDetailsActivityTest extends InjectedInstrumentationTest
         matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
   }

-  @Test public void shouldShowsConnectionErrorIfHaveConnectionThroubles() throws Exception {
+  @Test public void shouldShowConnectionErrorIfHaveConnectionTroubles() throws Exception {
     givenConnectionExceptionObtainingComicSeries();

     startActivity();
@@ -125,7 +125,7 @@ public class ComicSeriesDetailsActivityTest extends InjectedInstrumentationTest
   }

   private ComicSeries givenValidComicSeries() throws Exception {
-    ComicSeries comicSeries = getComicSeries(ANY_COMIC_SERIE_ID);
+    ComicSeries comicSeries = getComicSeries(ANY_COMIC_SERIES_ID);
     when(comicSeriesRepository.getComicSeriesDetail(any(Integer.class))).thenReturn(
         comicSeries);
     return comicSeries;
@@ -175,7 +175,7 @@ public class ComicSeriesDetailsActivityTest extends InjectedInstrumentationTest

   private ComicSeriesDetailsActivity startActivity() {
     Intent intent = new Intent();
-    intent.putExtra("ComicSeriesDetailsActivity.ComicSeriesKey", ANY_COMIC_SERIE_ID);
+    intent.putExtra("ComicSeriesDetailsActivity.ComicSeriesKey", ANY_COMIC_SERIES_ID);

     return activityRule.launchActivity(intent);
   }
diff --git a/sample/src/androidTest/java/com/karumi/rosie/sample/main/view/activity/MainActivityTest.java b/sample/src/androidTest/java/com/karumi/rosie/sample/main/view/activity/MainActivityTest.java
index 672aefc..366da3a 100644
--- a/sample/src/androidTest/java/com/karumi/rosie/sample/main/view/activity/MainActivityTest.java
+++ b/sample/src/androidTest/java/com/karumi/rosie/sample/main/view/activity/MainActivityTest.java
@@ -90,7 +90,7 @@ import static org.mockito.Mockito.when;
   @Rule public IntentsTestRule<MainActivity> activityRule =
       new IntentsTestRule<>(MainActivity.class, true, false);

-  @Test public void shouldShowsFakeDataBarWhenMarvelKeysNotHasBeenProvided() throws Exception {
+  @Test public void shouldShowFakeDataBarWhenMarvelKeysHasNotBeenProvided() throws Exception {
     givenFakeDataIsEnable();
     givenEmptyCharacters();
     givenEmptyComicSeries();
@@ -100,7 +100,7 @@ import static org.mockito.Mockito.when;
     onView(withId(R.id.tv_disclaimer)).check(matches(isDisplayed()));
   }

-  @Test public void shouldShowsErrorIfSomethingWrongHappend() throws Exception {
+  @Test public void shouldShowErrorIfSomethingWrongHappens() throws Exception {
     givenExceptionObtainingCharacters();
     givenEmptyComicSeries();

@@ -110,7 +110,7 @@ import static org.mockito.Mockito.when;
         matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
   }

-  @Test public void shouldShowsConnectionErrorIfHaveConnectionThroubles() throws Exception {
+  @Test public void shouldShowConnectionErrorIfHaveConnectionTroubles() throws Exception {
     givenConnectionExceptionObtainingCharacters();
     givenEmptyComicSeries();

@@ -130,7 +130,7 @@ import static org.mockito.Mockito.when;
         matches(not(isDisplayed())));
   }

-  @Test public void shouldShowsCharacterNameIfThereAreCharacters() throws Exception {
+  @Test public void shouldShowCharacterNameIfThereAreCharacters() throws Exception {
     List<Character> superHeroes = givenThereAreSomeCharacters(ANY_NUMBER_OF_CHARACTERS);

     startActivity();
@@ -157,7 +157,7 @@ import static org.mockito.Mockito.when;
     intended(hasExtra("CharacterDetailsActivity.CharacterKey", characterSelected.getKey()));
   }

-  @Test public void shouldShowsComicSeriesIfTheAreComicSeriesAndTabIsShowed() throws Exception {
+  @Test public void shouldShowComicSeriesIfTheAreComicSeriesAndTabIsShown() throws Exception {
     givenThereAreSomeCharacters(ANY_NUMBER_OF_CHARACTERS);
     List<ComicSeries> comicSeries = givenThereAreSomeComicSeries(ANY_NUMBER_OF_COMIC_SERIES);

@@ -281,7 +281,7 @@ import static org.mockito.Mockito.when;
     ComicSeries comicSeries = new ComicSeries();
     comicSeries.setKey(id);
     comicSeries.setName("ComicSeries - " + id);
-    comicSeries.setDescription("Description Comic Serie - " + id);
+    comicSeries.setDescription("Description Comic Series - " + id);
     return comicSeries;
   }


/*
* http://blog.sqisland.com/2015/05/espresso-match-toolbar-title.html
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not right xD

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy paste :P


onView(allOf(withId(android.support.design.R.id.snackbar_text),
withText("Connection troubles. Ask to Ironman!"))).check(
matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you use isDisplayed instead of this withEffectiveVisibility?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this comes when I had a lot of problems with tests, and I made a lot of crazy things

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some tests and I have problems with snackbars and isDisplayed :S

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@pedrovgs
Copy link
Contributor

Good job @flipper83! 👍 Just minor comments.

@flipper83
Copy link
Member Author

PR updated, please review the Readme changes, my english is not the same.

@@ -248,6 +248,31 @@ public class SamplePresenter extends RosiePresenter<SamplePresenter.View> {
/*...*/
}
```
You can create your own factory that converts Exceptions to Error, here you can unify errors or add UI related info to your errors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create your own ErrorFactory implementation to map Exceptions to Errors. In your implementation you can unify your error handling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@pedrovgs
Copy link
Contributor

Review the comments about the README.md and we are ready to publish!

@Serchinastico
Copy link
Contributor

👍

flipper83 added a commit that referenced this pull request Feb 24, 2016
@flipper83 flipper83 merged commit 243b9f1 into master Feb 24, 2016
@flipper83 flipper83 deleted the sample-tests branch February 24, 2016 18:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants