File tree Expand file tree Collapse file tree 2 files changed +71
-1
lines changed
main/java/rx/android/view
test/java/rx/android/view Expand file tree Collapse file tree 2 files changed +71
-1
lines changed Original file line number Diff line number Diff line change 14
14
package rx .android .view ;
15
15
16
16
import android .view .View ;
17
-
17
+ import android . widget . TextView ;
18
18
import rx .functions .Action1 ;
19
19
20
20
/**
@@ -112,4 +112,28 @@ public static Action1<? super Boolean> setVisibility(View view) {
112
112
public static Action1 <? super Boolean > setVisibility (View view , int visibilityOnFalse ) {
113
113
return new ViewActionSetVisibility (view , visibilityOnFalse );
114
114
}
115
+
116
+ /**
117
+ * Set the text of a {@link TextView} based on values emitted by an Observable.
118
+ */
119
+ public static Action1 <? super CharSequence > setText (final TextView textView ) {
120
+ return new Action1 <CharSequence >() {
121
+ @ Override
122
+ public void call (CharSequence charSequence ) {
123
+ textView .setText (charSequence );
124
+ }
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Set the text of a {@link TextView} based on values emitted by an Observable.
130
+ */
131
+ public static Action1 <? super Integer > setTextResource (final TextView textView ) {
132
+ return new Action1 <Integer >() {
133
+ @ Override
134
+ public void call (Integer integer ) {
135
+ textView .setText (integer );
136
+ }
137
+ };
138
+ }
115
139
}
Original file line number Diff line number Diff line change
1
+ package rx .android .view ;
2
+
3
+ import android .widget .TextView ;
4
+ import org .junit .Before ;
5
+ import org .junit .Test ;
6
+ import org .junit .runner .RunWith ;
7
+ import org .mockito .Mockito ;
8
+ import org .robolectric .RobolectricTestRunner ;
9
+ import rx .subjects .PublishSubject ;
10
+
11
+ import static org .mockito .Mockito .verify ;
12
+
13
+ @ RunWith (RobolectricTestRunner .class )
14
+ public class ViewActionSetTextTest {
15
+
16
+ private TextView textView ;
17
+
18
+ @ Before
19
+ public void setUp () {
20
+ textView = Mockito .mock (TextView .class );
21
+ }
22
+
23
+ @ Test
24
+ public void testSetsTextViewCharSequence () {
25
+ final PublishSubject <String > subject = PublishSubject .create ();
26
+ subject .subscribe (ViewActions .setText (textView ));
27
+
28
+ subject .onNext ("Hello" );
29
+ verify (textView ).setText ("Hello" );
30
+
31
+ subject .onNext ("World" );
32
+ verify (textView ).setText ("World" );
33
+ }
34
+
35
+ @ Test
36
+ public void testSetsTextViewTextResource () {
37
+ final PublishSubject <Integer > subject = PublishSubject .create ();
38
+ subject .subscribe (ViewActions .setTextResource (textView ));
39
+
40
+ subject .onNext (1 );
41
+ verify (textView ).setText (1 );
42
+
43
+ subject .onNext (3 );
44
+ verify (textView ).setText (3 );
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments