-
Notifications
You must be signed in to change notification settings - Fork 2
/
CaptureInstrumentedTest.java
173 lines (141 loc) · 6.55 KB
/
CaptureInstrumentedTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package info.dourok.esactivity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import info.dourok.esactivity.activity.CaptureTestActivity;
import info.dourok.esactivity.test.R;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static info.dourok.esactivity.util.EspressoHelper.getActivityInstance;
import static org.hamcrest.Matchers.not;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class CaptureInstrumentedTest {
@Rule
public ActivityTestRule<CaptureTestActivity> mActivityRule =
new ActivityTestRule<>(CaptureTestActivity.class);
@Test
public void activity__ref_should_be_updated_after_activity_recreate() {
String id = getActivityInstance().toString();
onView(withText("captureActivity")).perform(click());
getInstrumentation().runOnMainSync(() -> mActivityRule.getActivity().recreate());
pressBack();
String idNew = getActivityInstance().toString();
onView(withId(R.id.content)).check(matches(not(withText(id))));
onView(withId(R.id.content)).check(matches(withText(idNew)));
}
@Test
public void view_with_id__ref_should_be_updated_after_activity_recreate() {
final String text = "text";
onView(withText("captureViewWithId")).perform(click());
getInstrumentation().runOnMainSync(() -> mActivityRule.getActivity().recreate());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void fragment_with_id__ref_should_be_updated_after_activity_recreate() {
final String text = "text";
onView(withText("captureFragmentWithId")).perform(click());
getInstrumentation().runOnMainSync(() -> mActivityRule.getActivity().recreate());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void fragment_with_tag__ref_should_be_updated_after_activity_recreate() {
final String text = "text";
onView(withText("captureFragmentWithTag")).perform(click());
getInstrumentation().runOnMainSync(() -> mActivityRule.getActivity().recreate());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void support_fragment_with_id__ref_should_be_updated_after_activity_recreate() {
final String text = "text";
onView(withText("captureSupportFragmentWithId")).perform(click());
getInstrumentation().runOnMainSync(() -> mActivityRule.getActivity().recreate());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void support_fragment_with_tag__ref_should_be_updated_after_activity_recreate() {
final String text = "text";
onView(withText("captureSupportFragmentWithTag")).perform(click());
getInstrumentation().runOnMainSync(() -> mActivityRule.getActivity().recreate());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void method__ref_should_be_updated_after_activity_recreate() throws Exception {
final String text = "text";
onView(withText("methodRef")).perform(click());
getInstrumentation().runOnMainSync(() -> mActivityRule.getActivity().recreate());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void view_with_id__ref_should_work() {
final String text = "text";
onView(withText("captureViewWithId")).perform(click());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void fragment_with_id__ref_should_work() {
final String text = "text";
onView(withText("captureFragmentWithId")).perform(click());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void fragment_with_tag__ref_should_work() {
final String text = "text";
onView(withText("captureFragmentWithTag")).perform(click());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void support_fragment_with_id__ref_should_work() {
final String text = "text";
onView(withText("captureSupportFragmentWithId")).perform(click());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void support_fragment_with_tag__ref_should_work() {
final String text = "text";
onView(withText("captureSupportFragmentWithTag")).perform(click());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
@Test
public void method__ref_should_work() throws Exception {
final String text = "text";
onView(withText("methodRef")).perform(click());
onView(withId(R.id.edit_text)).perform(replaceText(text));
onView(withId(R.id.action_ok)).perform(click());
onView(withId(R.id.content)).check(matches(withText(text)));
}
}