Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwdunlop committed Mar 26, 2019
2 parents 14cb362 + 0b08a7e commit 1481529
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> option;

private final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
private final ActivityTestRule<SingleFragmentActivity> mAnnouncementActivityTestRule =
new ActivityTestRule<SingleFragmentActivity>(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));



}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ limitations under the License.
<activity android:name=".ui.userprofile.UserProfileActivity"/>
<activity android:name=".ui.favouriteworkflow.FavouriteWorkflowsActivity"/>
<activity android:name=".ui.myworkflows.MyWorkflowActivity"/>
<activity android:name=".SingleFragmentActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-v21/ids.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="container1"></item>
</resources>

0 comments on commit 1481529

Please sign in to comment.