From 2890cb33c5f5633df5f9099f5fe879146b74501d Mon Sep 17 00:00:00 2001 From: Ana Date: Wed, 23 Nov 2016 11:23:51 +0100 Subject: [PATCH] Added all test for NavigationJobs --- .../jobs/NavigationJobsSpecification.scala | 143 ++++++++++++++++++ .../src/main/java/android/os/Bundle.java | 8 +- 2 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 modules/app/src/test/scala/cards/nine/app/ui/collections/jobs/NavigationJobsSpecification.scala diff --git a/modules/app/src/test/scala/cards/nine/app/ui/collections/jobs/NavigationJobsSpecification.scala b/modules/app/src/test/scala/cards/nine/app/ui/collections/jobs/NavigationJobsSpecification.scala new file mode 100644 index 000000000..23f8dc596 --- /dev/null +++ b/modules/app/src/test/scala/cards/nine/app/ui/collections/jobs/NavigationJobsSpecification.scala @@ -0,0 +1,143 @@ +package cards.nine.app.ui.collections.jobs + +import android.os.Bundle +import cards.nine.app.ui.collections.jobs.uiactions.{GroupCollectionsDOM, GroupCollectionsUiActions, NavigationUiActions} +import cards.nine.commons.test.TaskServiceSpecification +import cards.nine.commons.test.data.CollectionTestData +import macroid.ActivityContextWrapper +import org.specs2.mock.Mockito +import org.specs2.specification.Scope + + +trait NavigationJobsSpecification extends TaskServiceSpecification + with Mockito + with CollectionTestData { + + + trait NavigationJobsScope + extends Scope { + + implicit val contextWrapper = mock[ActivityContextWrapper] + + implicit val mockGroupCollectionsJobs = mock[GroupCollectionsJobs] + + implicit val mockSingleCollectionJobs = mock[SingleCollectionJobs] + + val mockGroupCollectionsDOM = mock[GroupCollectionsDOM] + + val mockGroupCollectionsUiActions = mock[GroupCollectionsUiActions] + + val mockNavigationUiActions = mock[NavigationUiActions] + + mockNavigationUiActions.dom returns mockGroupCollectionsDOM + + val mockBundle = mock[Bundle] + + val navigationJobs = new NavigationJobs(mockGroupCollectionsUiActions, mockNavigationUiActions)(contextWrapper) + + } +} + +class NavigationJobsSpec + extends NavigationJobsSpecification { + + "showAppDialog" should { + "call to openApps" in new NavigationJobsScope { + + mockGroupCollectionsDOM.getCurrentCollection returns Option(collection) + mockNavigationUiActions.openApps(any)(any, any) returns serviceRight(Unit) + + navigationJobs.showAppDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + + there was two(mockGroupCollectionsDOM).getCurrentCollection + there was one(mockNavigationUiActions).openApps(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs))) + } + + "call to openApps when current collection is None" in new NavigationJobsScope { + + mockGroupCollectionsDOM.getCurrentCollection returns None + mockNavigationUiActions.openApps(any)(any, any) returns serviceRight(Unit) + + navigationJobs.showAppDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + + there was two(mockGroupCollectionsDOM).getCurrentCollection + there was one(mockNavigationUiActions).openApps(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs))) + } + } + + "showRecommendationDialog" should { + + "call to openRecommendations" in new NavigationJobsScope { + + mockGroupCollectionsDOM.getCurrentCollection returns Option(collection) + mockNavigationUiActions.openRecommendations(any)(any, any) returns serviceRight(Unit) + + navigationJobs.showRecommendationDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + + there was two(mockGroupCollectionsDOM).getCurrentCollection + there was one(mockNavigationUiActions).openRecommendations(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs))) + } + + "shows a message of ContactUsError when current collection doesn't have appCategory and their cards doesn't have packageName" in new NavigationJobsScope { + + mockGroupCollectionsDOM.getCurrentCollection returns Option(collection.copy(appsCategory = None, cards = collection.cards.map (_.copy(packageName = None)))) + mockGroupCollectionsUiActions.showContactUsError() returns serviceRight(Unit) + + navigationJobs.showRecommendationDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + + there was one(mockGroupCollectionsDOM).getCurrentCollection + there was one(mockGroupCollectionsUiActions).showContactUsError() + } + + "shows a message of ContactUsError when current collection is None" in new NavigationJobsScope { + + mockGroupCollectionsDOM.getCurrentCollection returns None + mockGroupCollectionsUiActions.showContactUsError() returns serviceRight(Unit) + + navigationJobs.showRecommendationDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + + there was one(mockGroupCollectionsDOM).getCurrentCollection + there was one(mockGroupCollectionsUiActions).showContactUsError() + } + } + + "showContactsDialog" should { + "call to openContacts" in new NavigationJobsScope { + + mockNavigationUiActions.openContacts(any)(any, any) returns serviceRight(Unit) + mockGroupCollectionsDOM.getCurrentCollection returns Option(collection) + + navigationJobs.showContactsDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + there was one(mockNavigationUiActions).openContacts(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs))) + } + + "call to openContacts when current collection is None" in new NavigationJobsScope { + + mockNavigationUiActions.openContacts(any)(any, any) returns serviceRight(Unit) + mockGroupCollectionsDOM.getCurrentCollection returns None + + navigationJobs.showContactsDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + there was one(mockNavigationUiActions).openContacts(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs))) + } + } + + "showShortcutDialog" should { + "call to openShortcuts" in new NavigationJobsScope { + + mockNavigationUiActions.openShortcuts(any)(any, any) returns serviceRight(Unit) + mockGroupCollectionsDOM.getCurrentCollection returns Option(collection) + + navigationJobs.showShortcutDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + there was one(mockNavigationUiActions).openShortcuts(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs))) + } + + "call to openShortcuts when current collection is None" in new NavigationJobsScope { + + mockNavigationUiActions.openShortcuts(any)(any, any) returns serviceRight(Unit) + mockGroupCollectionsDOM.getCurrentCollection returns None + + navigationJobs.showShortcutDialog()(mockGroupCollectionsJobs, Option(mockSingleCollectionJobs)).mustRightUnit + there was one(mockNavigationUiActions).openShortcuts(any)(===(mockGroupCollectionsJobs), ===(Option(mockSingleCollectionJobs))) + } + } +} \ No newline at end of file diff --git a/modules/mock-android/src/main/java/android/os/Bundle.java b/modules/mock-android/src/main/java/android/os/Bundle.java index 59b88219a..007cab669 100644 --- a/modules/mock-android/src/main/java/android/os/Bundle.java +++ b/modules/mock-android/src/main/java/android/os/Bundle.java @@ -7,7 +7,7 @@ public class Bundle implements Parcelable, Cloneable { public static final Bundle EMPTY = null; public static final Creator CREATOR = null; -public Bundle() { throw new RuntimeException("Stub!"); } +public Bundle() { } public Bundle(ClassLoader loader) { throw new RuntimeException("Stub!"); } public Bundle(int capacity) { throw new RuntimeException("Stub!"); } public Bundle(Bundle b) { throw new RuntimeException("Stub!"); } @@ -27,11 +27,11 @@ public class Bundle implements Parcelable, Cloneable { public void putByte(String key, byte value) { throw new RuntimeException("Stub!"); } public void putChar(String key, char value) { throw new RuntimeException("Stub!"); } public void putShort(String key, short value) { throw new RuntimeException("Stub!"); } -public void putInt(String key, int value) { throw new RuntimeException("Stub!"); } +public void putInt(String key, int value) { } public void putLong(String key, long value) { throw new RuntimeException("Stub!"); } public void putFloat(String key, float value) { throw new RuntimeException("Stub!"); } public void putDouble(String key, double value) { throw new RuntimeException("Stub!"); } -public void putString(String key, String value) { throw new RuntimeException("Stub!"); } +public void putString(String key, String value) { } public void putCharSequence(String key, CharSequence value) { throw new RuntimeException("Stub!"); } public void putParcelable(String key, Parcelable value) { throw new RuntimeException("Stub!"); } public void putParcelableArray(String key, Parcelable[] value) { throw new RuntimeException("Stub!"); } @@ -49,7 +49,7 @@ public class Bundle implements Parcelable, Cloneable { public void putLongArray(String key, long[] value) { throw new RuntimeException("Stub!"); } public void putFloatArray(String key, float[] value) { throw new RuntimeException("Stub!"); } public void putDoubleArray(String key, double[] value) { throw new RuntimeException("Stub!"); } -public void putStringArray(String key, String[] value) { throw new RuntimeException("Stub!"); } +public void putStringArray(String key, String[] value) { } public void putCharSequenceArray(String key, CharSequence[] value) { throw new RuntimeException("Stub!"); } public void putBundle(String key, Bundle value) { throw new RuntimeException("Stub!"); } public boolean getBoolean(String key) { throw new RuntimeException("Stub!"); }