Skip to content

Commit 1481529

Browse files
committed
2 parents 14cb362 + 0b08a7e commit 1481529

File tree

13 files changed

+169
-6
lines changed

13 files changed

+169
-6
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ android:
2424
- extra-google-google_play_services
2525
- extra-android-m2repository
2626
- extra-google-m2repository
27-
- build-tools-27.0.3
28-
- android-27
27+
- build-tools-28.0.3
28+
- android-28
2929

3030
before_install:
31-
- yes | sdkmanager "platforms;android-27"
31+
- yes | sdkmanager "platforms;android-28"
3232

3333
script: "./gradlew build --stacktrace"

app/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ android {
3232
androidTest {
3333
java.srcDirs = ['src/androidTest/java/']
3434
java.srcDir commonTestDir
35+
resources.srcDirs += 'src/commonTest/resources'
36+
3537
}
3638
test {
3739
java.srcDirs = ['src/test/java/']
3840
java.srcDir commonTestDir
41+
resources.srcDirs += 'src/commonTest/resources'
3942
}
4043
}
4144

@@ -56,6 +59,10 @@ android {
5659
packagingOptions {
5760
exclude 'META-INF/rxjava.properties'
5861
}
62+
compileOptions {
63+
sourceCompatibility JavaVersion.VERSION_1_8
64+
targetCompatibility JavaVersion.VERSION_1_8
65+
}
5966

6067
buildToolsVersion rootProject.ext.buildToolsVersion
6168
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.apache.taverna.mobile.announcement;
2+
3+
import org.apache.taverna.mobile.FakeRemoteDataSource;
4+
import org.apache.taverna.mobile.R;
5+
import org.apache.taverna.mobile.SingleFragmentActivity;
6+
import org.apache.taverna.mobile.TestComponentRule;
7+
import org.apache.taverna.mobile.data.model.Announcements;
8+
import org.apache.taverna.mobile.ui.anouncements.AnnouncementFragment;
9+
import org.apache.taverna.mobile.utils.RecyclerViewItemCountAssertion;
10+
import org.junit.Before;
11+
import org.junit.Rule;
12+
import org.junit.Test;
13+
import org.junit.rules.RuleChain;
14+
import org.junit.rules.TestRule;
15+
import org.junit.runner.RunWith;
16+
import org.mockito.Mockito;
17+
18+
import android.content.Intent;
19+
import android.support.test.InstrumentationRegistry;
20+
import android.support.test.rule.ActivityTestRule;
21+
import android.support.test.runner.AndroidJUnit4;
22+
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
26+
import io.reactivex.Observable;
27+
28+
import static android.os.SystemClock.sleep;
29+
import static android.support.test.espresso.Espresso.onView;
30+
import static android.support.test.espresso.assertion.ViewAssertions.matches;
31+
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
32+
import static android.support.test.espresso.matcher.ViewMatchers.withId;
33+
34+
@RunWith(AndroidJUnit4.class)
35+
public class AnnouncementActivityTest {
36+
37+
private Announcements announcements;
38+
private Map<String, String> option;
39+
40+
private final TestComponentRule component =
41+
new TestComponentRule(InstrumentationRegistry.getTargetContext());
42+
private final ActivityTestRule<SingleFragmentActivity> mAnnouncementActivityTestRule =
43+
new ActivityTestRule<SingleFragmentActivity>(SingleFragmentActivity.class,
44+
false, false) {
45+
@Override
46+
protected Intent getActivityIntent() {
47+
48+
return new Intent(InstrumentationRegistry.getTargetContext(),
49+
SingleFragmentActivity.class);
50+
}
51+
};
52+
53+
/**
54+
* TestComponentRule needs to go first to make sure the Dagger ApplicationTestComponent is set
55+
* in the Application before any Activity is launched.
56+
*/
57+
@Rule
58+
public final TestRule chain = RuleChain.outerRule(component)
59+
.around(mAnnouncementActivityTestRule);
60+
61+
62+
@Before
63+
public void setUp() {
64+
announcements = FakeRemoteDataSource.getAnnouncements();
65+
option = new HashMap<>();
66+
option.put("order", "reverse");
67+
option.put("page", String.valueOf(1));
68+
}
69+
70+
@Test
71+
public void CheckIfRecyclerViewIsLoaded() {
72+
73+
74+
Mockito.when(component.getMockDataManager().getAllAnnouncement(option))
75+
.thenReturn(Observable.just(announcements));
76+
mAnnouncementActivityTestRule.launchActivity(null);
77+
mAnnouncementActivityTestRule.getActivity().setFragment(new AnnouncementFragment());
78+
79+
onView(withId(R.id.rv_movies)).check(new RecyclerViewItemCountAssertion(5));
80+
81+
82+
83+
}
84+
85+
86+
}

app/src/androidTest/java/org/apache/taverna/mobile/login/LoginActivityTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@
4040
import android.support.test.runner.AndroidJUnit4;
4141

4242
import io.reactivex.Observable;
43-
import retrofit2.HttpException;
4443

4544
import static android.os.SystemClock.sleep;
4645
import static android.support.test.espresso.Espresso.onView;
4746
import static android.support.test.espresso.action.ViewActions.click;
4847
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
49-
import static android.support.test.espresso.action.ViewActions.scrollTo;
5048
import static android.support.test.espresso.action.ViewActions.typeText;
5149
import static android.support.test.espresso.assertion.ViewAssertions.matches;
5250
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.apache.taverna.mobile.utils;
2+
3+
import android.support.test.espresso.NoMatchingViewException;
4+
import android.support.test.espresso.ViewAssertion;
5+
import android.support.test.espresso.matcher.ViewMatchers;
6+
import android.support.v7.widget.RecyclerView;
7+
import android.view.View;
8+
import static org.hamcrest.Matchers.equalTo;
9+
10+
11+
public class RecyclerViewItemCountAssertion implements ViewAssertion {
12+
private final int expectedCount;
13+
14+
public RecyclerViewItemCountAssertion(int expectedCount) {
15+
this.expectedCount = expectedCount;
16+
}
17+
18+
@Override
19+
public void check(View view, NoMatchingViewException noViewFoundException) {
20+
if (noViewFoundException != null) {
21+
throw noViewFoundException;
22+
}
23+
24+
RecyclerView recyclerView = (RecyclerView) view;
25+
RecyclerView.Adapter adapter = recyclerView.getAdapter();
26+
ViewMatchers.assertThat(adapter.getItemCount(), equalTo(5));
27+
}
28+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ limitations under the License.
107107
<activity android:name=".ui.userprofile.UserProfileActivity"/>
108108
<activity android:name=".ui.favouriteworkflow.FavouriteWorkflowsActivity"/>
109109
<activity android:name=".ui.myworkflows.MyWorkflowActivity"/>
110+
<activity android:name=".SingleFragmentActivity"/>
110111
</application>
111112

112113
</manifest>

0 commit comments

Comments
 (0)