diff --git a/.travis.yml b/.travis.yml index 68462644..4463448b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,10 +24,10 @@ android: - extra-google-google_play_services - extra-android-m2repository - extra-google-m2repository - - build-tools-27.0.3 - - android-27 + - build-tools-28.0.3 + - android-28 before_install: - - yes | sdkmanager "platforms;android-27" + - yes | sdkmanager "platforms;android-28" script: "./gradlew build --stacktrace" diff --git a/app/build.gradle b/app/build.gradle index dfdbd44c..145d2afb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,10 +32,13 @@ android { androidTest { java.srcDirs = ['src/androidTest/java/'] java.srcDir commonTestDir + resources.srcDirs += 'src/commonTest/resources' + } test { java.srcDirs = ['src/test/java/'] java.srcDir commonTestDir + resources.srcDirs += 'src/commonTest/resources' } } @@ -56,6 +59,10 @@ android { packagingOptions { exclude 'META-INF/rxjava.properties' } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } buildToolsVersion rootProject.ext.buildToolsVersion } diff --git a/app/src/androidTest/java/org/apache/taverna/mobile/announcement/AnnouncementActivityTest.java b/app/src/androidTest/java/org/apache/taverna/mobile/announcement/AnnouncementActivityTest.java new file mode 100644 index 00000000..f918d776 --- /dev/null +++ b/app/src/androidTest/java/org/apache/taverna/mobile/announcement/AnnouncementActivityTest.java @@ -0,0 +1,86 @@ +package org.apache.taverna.mobile.announcement; + +import org.apache.taverna.mobile.FakeRemoteDataSource; +import org.apache.taverna.mobile.R; +import org.apache.taverna.mobile.SingleFragmentActivity; +import org.apache.taverna.mobile.TestComponentRule; +import org.apache.taverna.mobile.data.model.Announcements; +import org.apache.taverna.mobile.ui.anouncements.AnnouncementFragment; +import org.apache.taverna.mobile.utils.RecyclerViewItemCountAssertion; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.RuleChain; +import org.junit.rules.TestRule; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import android.content.Intent; +import android.support.test.InstrumentationRegistry; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; + +import java.util.HashMap; +import java.util.Map; + +import io.reactivex.Observable; + +import static android.os.SystemClock.sleep; +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +@RunWith(AndroidJUnit4.class) +public class AnnouncementActivityTest { + + private Announcements announcements; + private Map option; + + private final TestComponentRule component = + new TestComponentRule(InstrumentationRegistry.getTargetContext()); + private final ActivityTestRule mAnnouncementActivityTestRule = + new ActivityTestRule(SingleFragmentActivity.class, + false, false) { + @Override + protected Intent getActivityIntent() { + + return new Intent(InstrumentationRegistry.getTargetContext(), + SingleFragmentActivity.class); + } + }; + + /** + * TestComponentRule needs to go first to make sure the Dagger ApplicationTestComponent is set + * in the Application before any Activity is launched. + */ + @Rule + public final TestRule chain = RuleChain.outerRule(component) + .around(mAnnouncementActivityTestRule); + + + @Before + public void setUp() { + announcements = FakeRemoteDataSource.getAnnouncements(); + option = new HashMap<>(); + option.put("order", "reverse"); + option.put("page", String.valueOf(1)); + } + + @Test + public void CheckIfRecyclerViewIsLoaded() { + + + Mockito.when(component.getMockDataManager().getAllAnnouncement(option)) + .thenReturn(Observable.just(announcements)); + mAnnouncementActivityTestRule.launchActivity(null); + mAnnouncementActivityTestRule.getActivity().setFragment(new AnnouncementFragment()); + + onView(withId(R.id.rv_movies)).check(new RecyclerViewItemCountAssertion(5)); + + + + } + + +} diff --git a/app/src/androidTest/java/org/apache/taverna/mobile/login/LoginActivityTest.java b/app/src/androidTest/java/org/apache/taverna/mobile/login/LoginActivityTest.java index ba52fb83..b94a5e76 100644 --- a/app/src/androidTest/java/org/apache/taverna/mobile/login/LoginActivityTest.java +++ b/app/src/androidTest/java/org/apache/taverna/mobile/login/LoginActivityTest.java @@ -40,13 +40,11 @@ import android.support.test.runner.AndroidJUnit4; import io.reactivex.Observable; -import retrofit2.HttpException; import static android.os.SystemClock.sleep; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; -import static android.support.test.espresso.action.ViewActions.scrollTo; import static android.support.test.espresso.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; diff --git a/app/src/androidTest/java/org/apache/taverna/mobile/utils/RecyclerViewItemCountAssertion.java b/app/src/androidTest/java/org/apache/taverna/mobile/utils/RecyclerViewItemCountAssertion.java new file mode 100644 index 00000000..27cfcc3f --- /dev/null +++ b/app/src/androidTest/java/org/apache/taverna/mobile/utils/RecyclerViewItemCountAssertion.java @@ -0,0 +1,28 @@ +package org.apache.taverna.mobile.utils; + +import android.support.test.espresso.NoMatchingViewException; +import android.support.test.espresso.ViewAssertion; +import android.support.test.espresso.matcher.ViewMatchers; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import static org.hamcrest.Matchers.equalTo; + + +public class RecyclerViewItemCountAssertion implements ViewAssertion { + private final int expectedCount; + + public RecyclerViewItemCountAssertion(int expectedCount) { + this.expectedCount = expectedCount; + } + + @Override + public void check(View view, NoMatchingViewException noViewFoundException) { + if (noViewFoundException != null) { + throw noViewFoundException; + } + + RecyclerView recyclerView = (RecyclerView) view; + RecyclerView.Adapter adapter = recyclerView.getAdapter(); + ViewMatchers.assertThat(adapter.getItemCount(), equalTo(5)); + } +} \ No newline at end of file diff --git a/app/src/test/resources/announcement.xml b/app/src/commonTest/resources/announcement.xml similarity index 100% rename from app/src/test/resources/announcement.xml rename to app/src/commonTest/resources/announcement.xml diff --git a/app/src/test/resources/announcements.xml b/app/src/commonTest/resources/announcements.xml similarity index 100% rename from app/src/test/resources/announcements.xml rename to app/src/commonTest/resources/announcements.xml diff --git a/app/src/test/resources/user.xml b/app/src/commonTest/resources/user.xml similarity index 100% rename from app/src/test/resources/user.xml rename to app/src/commonTest/resources/user.xml diff --git a/app/src/test/resources/workflows.xml b/app/src/commonTest/resources/workflows.xml similarity index 100% rename from app/src/test/resources/workflows.xml rename to app/src/commonTest/resources/workflows.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cdf5e287..75ea3a44 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -107,6 +107,7 @@ limitations under the License. + \ No newline at end of file diff --git a/app/src/main/java/org/apache/taverna/mobile/SingleFragmentActivity.java b/app/src/main/java/org/apache/taverna/mobile/SingleFragmentActivity.java new file mode 100644 index 00000000..7f8e5369 --- /dev/null +++ b/app/src/main/java/org/apache/taverna/mobile/SingleFragmentActivity.java @@ -0,0 +1,36 @@ +package org.apache.taverna.mobile; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +import org.apache.taverna.mobile.ui.base.BaseActivity; + +public class SingleFragmentActivity extends BaseActivity { + FrameLayout content; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + content = new FrameLayout(this); + content.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + content.setId(R.id.container1); + setContentView(content); + } + + public void setFragment(Fragment fragment) { + + getSupportFragmentManager().beginTransaction() + .add(R.id.container1, fragment, "TEST") + .commit(); + } + + public void replaceFragment(Fragment fragment) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.container1, fragment).commit(); + } + +} diff --git a/app/src/main/java/org/apache/taverna/mobile/ui/anouncements/AnnouncementFragment.java b/app/src/main/java/org/apache/taverna/mobile/ui/anouncements/AnnouncementFragment.java index ba56eaa1..fc54d8da 100644 --- a/app/src/main/java/org/apache/taverna/mobile/ui/anouncements/AnnouncementFragment.java +++ b/app/src/main/java/org/apache/taverna/mobile/ui/anouncements/AnnouncementFragment.java @@ -54,6 +54,8 @@ import butterknife.BindView; import butterknife.ButterKnife; +import static android.support.design.widget.Snackbar.make; + public class AnnouncementFragment extends Fragment implements RecyclerItemClickListner .OnItemClickListener, AnnouncementMvpView { @@ -245,7 +247,8 @@ public void onResume() { @Override public void showSnackBar(int message) { - final Snackbar snackbar = Snackbar.make(mRecyclerView, message, Snackbar.LENGTH_LONG); + final Snackbar snackbar = make(getActivity().findViewById(android.R.id.content), + message, Snackbar.LENGTH_LONG); snackbar.setAction(getResources().getString(R.string.ok), new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/app/src/main/res/values-v21/ids.xml b/app/src/main/res/values-v21/ids.xml new file mode 100644 index 00000000..b7f89392 --- /dev/null +++ b/app/src/main/res/values-v21/ids.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file