-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incu…
- Loading branch information
Showing
13 changed files
with
169 additions
and
6 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
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
86 changes: 86 additions & 0 deletions
86
...src/androidTest/java/org/apache/taverna/mobile/announcement/AnnouncementActivityTest.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,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)); | ||
|
||
|
||
|
||
} | ||
|
||
|
||
} |
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
28 changes: 28 additions & 0 deletions
28
app/src/androidTest/java/org/apache/taverna/mobile/utils/RecyclerViewItemCountAssertion.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,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.
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
36 changes: 36 additions & 0 deletions
36
app/src/main/java/org/apache/taverna/mobile/SingleFragmentActivity.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,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(); | ||
} | ||
|
||
} |
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
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> |