-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FavoritesActivity tests are now using only two layers
- Loading branch information
1 parent
69e809d
commit ac6265a
Showing
11 changed files
with
117 additions
and
82 deletions.
There are no files selected for viewing
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
73 changes: 0 additions & 73 deletions
73
app/src/androidTest/java/io/catter2/FavoritesActivityTest.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
app/src/androidTest/java/io/catter2/favorites_activity/FavoritesActivityTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.catter2.favorites_activity; | ||
|
||
import android.content.Intent; | ||
import android.support.test.espresso.matcher.ViewMatchers; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import io.catter2.R; | ||
import io.catter2.espresso_utils.RecyclerViewItemCountAssertion; | ||
import io.catter2.favorites.FavoritesRepository; | ||
import io.catter2.favorites.GetFavoritesUseCase; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class FavoritesActivityTest { | ||
@Rule | ||
public ActivityTestRule<FavoritesActivity> activityRule = | ||
new ActivityTestRule<>(FavoritesActivity.class, true, false /* Do not launch activity! */); | ||
|
||
@Test | ||
public void testThereAreThreeImages() { | ||
final ArrayList<String> expectedUrls = new ArrayList<>(); | ||
expectedUrls.add("url0"); | ||
expectedUrls.add("url1"); | ||
expectedUrls.add("url2"); | ||
setUpGetFavoritesResponse(expectedUrls); | ||
|
||
activityRule.launchActivity(new Intent()); | ||
|
||
onView(ViewMatchers.withId(R.id.favorites_rv)).check(new RecyclerViewItemCountAssertion(3)); | ||
} | ||
|
||
@Test | ||
public void testThereAreZeroImages() { | ||
final ArrayList<String> expectedUrls = new ArrayList<>(); | ||
setUpGetFavoritesResponse(expectedUrls); | ||
|
||
activityRule.launchActivity(new Intent()); | ||
|
||
onView(ViewMatchers.withId(R.id.favorites_rv)).check(new RecyclerViewItemCountAssertion(0)); | ||
} | ||
|
||
private void setUpGetFavoritesResponse(final List<String> urls) { | ||
FavoritesActivityDIModule.testGetFavoritesUseCase = | ||
new GetFavoritesUseCase(mock(FavoritesRepository.class)) { | ||
@Override | ||
public void getFavorites(Callback callback) { | ||
callback.favoriteUrlsUpdated(urls); | ||
} | ||
}; | ||
} | ||
} |
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
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
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
15 changes: 15 additions & 0 deletions
15
app/src/main/java/io/catter2/favorites_activity/FavoritesActivityDIComponent.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.catter2.favorites_activity; | ||
|
||
import io.catter2.di.UserDIComponent; | ||
|
||
public class FavoritesActivityDIComponent { | ||
private FavoritesActivityDIModule module; | ||
|
||
public FavoritesActivityDIComponent() { | ||
this.module = new FavoritesActivityDIModule(UserDIComponent.get()); | ||
} | ||
|
||
public void inject(FavoritesActivity activity) { | ||
activity.injectGetFavoritesUserCase(module.provideGetFavoritesUseCase()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/io/catter2/favorites_activity/FavoritesActivityDIModule.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.catter2.favorites_activity; | ||
|
||
import io.catter2.di.UserDIComponent; | ||
import io.catter2.favorites.GetFavoritesUseCase; | ||
|
||
public class FavoritesActivityDIModule { | ||
public static GetFavoritesUseCase testGetFavoritesUseCase; | ||
|
||
private UserDIComponent userDIComponent; | ||
|
||
public FavoritesActivityDIModule(UserDIComponent userDIComponent) { | ||
this.userDIComponent = userDIComponent; | ||
} | ||
|
||
GetFavoritesUseCase provideGetFavoritesUseCase() { | ||
if (testGetFavoritesUseCase != null) { | ||
return testGetFavoritesUseCase; | ||
} | ||
|
||
return new GetFavoritesUseCase(userDIComponent.getFavoritesRepository()); | ||
} | ||
} |
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
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
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