21
21
22
22
package com .parse ;
23
23
24
+ import android .app .Activity ;
24
25
import android .database .DataSetObserver ;
26
+ import android .test .ActivityInstrumentationTestCase2 ;
25
27
import android .view .View ;
26
28
import android .widget .LinearLayout ;
27
29
import android .widget .ListView ;
49
51
import static org .mockito .Mockito .mock ;
50
52
import static org .mockito .Mockito .when ;
51
53
52
- public class ParseQueryAdapterTest extends BaseActivityInstrumentationTestCase2 <TestActivity > {
54
+ public class ParseQueryAdapterTest extends ActivityInstrumentationTestCase2 <TestActivity > {
53
55
54
56
@ ParseClassName ("Thing" )
55
57
public static class Thing extends ParseObject {
@@ -69,7 +71,7 @@ public ParseQueryAdapterTest() {
69
71
public void setUp () throws Exception {
70
72
super .setUp ();
71
73
72
- listView = new ListView (activity );
74
+ listView = new ListView (getActivity () );
73
75
savedThings = new ArrayList <>();
74
76
totalThings = 10 ;
75
77
@@ -141,7 +143,7 @@ public void tearDown() throws Exception {
141
143
}
142
144
143
145
public void testLoadObjects () throws Exception {
144
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
146
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
145
147
final Semaphore done = new Semaphore (0 );
146
148
adapter .addOnQueryLoadListener (new OnQueryLoadListener <Thing >() {
147
149
@ Override
@@ -164,7 +166,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
164
166
165
167
public void testLoadObjectsWithGenericParseObjects () throws Exception {
166
168
final ParseQueryAdapter <ParseObject > adapter =
167
- new ParseQueryAdapter <>(activity , Thing .class );
169
+ new ParseQueryAdapter <>(getActivity () , Thing .class );
168
170
final Semaphore done = new Semaphore (0 );
169
171
adapter .addOnQueryLoadListener (new OnQueryLoadListener <ParseObject >() {
170
172
@ Override
@@ -186,19 +188,19 @@ public void onLoaded(List<ParseObject> objects, Exception e) {
186
188
}
187
189
188
190
public void testGetItemViewWithTextKey () {
189
- ParseQueryAdapter < ParseObject > adapter =
190
- new ParseQueryAdapter <>(activity , Thing .class );
191
+ Activity activity = getActivity ();
192
+ ParseQueryAdapter < ParseObject > adapter = new ParseQueryAdapter <>(activity , Thing .class );
191
193
adapter .setTextKey ("name" );
192
194
193
- View view = adapter .getItemView (savedThings .get (0 ), buildReusableListCell (), listView );
195
+ View view = adapter .getItemView (savedThings .get (0 ), buildReusableListCell (activity ), listView );
194
196
TextView textView = (TextView ) view .findViewById (android .R .id .text1 );
195
197
196
198
assertEquals ("Thing 0" , textView .getText ());
197
199
}
198
200
199
201
public void testGetItemViewWithCustomLayout () {
200
202
ParseQueryAdapter <ParseObject > adapter =
201
- new ParseQueryAdapter <>(activity , Thing .class , R .layout .view_item );
203
+ new ParseQueryAdapter <>(getActivity () , Thing .class , R .layout .view_item );
202
204
adapter .setTextKey ("name" );
203
205
204
206
View view = adapter .getItemView (savedThings .get (0 ), null , listView );
@@ -211,7 +213,7 @@ public void testGetItemViewWithCustomLayout() {
211
213
212
214
public void testGetItemViewWithNoTextKey () throws ParseException {
213
215
ParseQueryAdapter <ParseObject > adapter =
214
- new ParseQueryAdapter <>(activity , Thing .class );
216
+ new ParseQueryAdapter <>(getActivity () , Thing .class );
215
217
216
218
View view = adapter .getItemView (savedThings .get (0 ), null , listView );
217
219
TextView textView = (TextView ) view .findViewById (android .R .id .text1 );
@@ -221,7 +223,7 @@ public void testGetItemViewWithNoTextKey() throws ParseException {
221
223
}
222
224
223
225
public void testLoadObjectsWithLimitsObjectsPerPage () throws Exception {
224
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
226
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
225
227
final int pageSize = 4 ;
226
228
adapter .setObjectsPerPage (pageSize );
227
229
final Capture <Integer > timesThrough = new Capture <>(0 );
@@ -268,7 +270,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
268
270
}
269
271
270
272
public void testLoadObjectsWithLimitsObjectsPerPageAndNoRemainder () throws Exception {
271
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
273
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
272
274
final int pageSize = 5 ;
273
275
adapter .setObjectsPerPage (pageSize );
274
276
final Capture <Integer > timesThrough = new Capture <>(0 );
@@ -311,7 +313,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
311
313
}
312
314
313
315
public void testLoadObjectsWithPaginationNextPageView () throws Exception {
314
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
316
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
315
317
final int pageSize = 5 ;
316
318
adapter .setObjectsPerPage (pageSize );
317
319
final Capture <Integer > timesThrough = new Capture <>(0 );
@@ -363,7 +365,7 @@ public void testLoadObjectsWithNoPagination() throws Exception {
363
365
}
364
366
totalThings += additional ;
365
367
366
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
368
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
367
369
adapter .setPaginationEnabled (false );
368
370
final Semaphore done = new Semaphore (0 );
369
371
adapter .addOnQueryLoadListener (new OnQueryLoadListener <Thing >() {
@@ -387,7 +389,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
387
389
}
388
390
389
391
public void testClear () throws Exception {
390
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
392
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
391
393
final Semaphore done = new Semaphore (0 );
392
394
final Capture <Integer > counter = new Capture <>(0 );
393
395
adapter .addOnQueryLoadListener (new OnQueryLoadListener <Thing >() {
@@ -433,7 +435,7 @@ public ParseQuery<Thing> create() {
433
435
}
434
436
};
435
437
436
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , factory );
438
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , factory );
437
439
final int pageSize = 5 ;
438
440
adapter .setObjectsPerPage (pageSize );
439
441
adapter .setPaginationEnabled (true );
@@ -497,7 +499,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
497
499
}
498
500
499
501
public void testLoadObjectsWithOnLoadingAndOnLoadedCallback () throws Exception {
500
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
502
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
501
503
adapter .setObjectsPerPage (5 );
502
504
final Capture <Boolean > flag = new Capture <>(false );
503
505
final Semaphore done = new Semaphore (0 );
@@ -525,7 +527,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
525
527
}
526
528
527
529
public void testLoadNextPageBeforeLoadObjects () throws Exception {
528
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
530
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
529
531
final Semaphore done = new Semaphore (0 );
530
532
adapter .addOnQueryLoadListener (new OnQueryLoadListener <Thing >() {
531
533
@ Override
@@ -547,7 +549,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
547
549
}
548
550
549
551
public void testIncomingQueryResultAfterClearing () throws Exception {
550
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
552
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
551
553
final int pageSize = 4 ;
552
554
adapter .setObjectsPerPage (pageSize );
553
555
final Semaphore done = new Semaphore (0 );
@@ -578,7 +580,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
578
580
public void testLoadObjectsWithOverrideSetPageOnQuery () throws Exception {
579
581
final int arbitraryLimit = 3 ;
580
582
final ParseQueryAdapter <Thing > adapter =
581
- new ParseQueryAdapter <Thing >(activity , Thing .class ) {
583
+ new ParseQueryAdapter <Thing >(getActivity () , Thing .class ) {
582
584
@ Override
583
585
public void setPageOnQuery (int page , ParseQuery <Thing > query ) {
584
586
// Make sure that this method is being used + respected.
@@ -605,7 +607,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
605
607
}
606
608
607
609
public void testLoadObjectsWithtAutoload () throws Exception {
608
- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
610
+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
609
611
final Capture <Boolean > flag = new Capture <>(false );
610
612
// Make sure that the Adapter doesn't start trying to load objects until AFTER we set this flag
611
613
// to true (= triggered by calling setAutoload, NOT registerDataSetObserver, if autoload is
@@ -634,7 +636,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
634
636
assertTrue (done .tryAcquire (10 , TimeUnit .SECONDS ));
635
637
}
636
638
637
- private LinearLayout buildReusableListCell () {
639
+ private static LinearLayout buildReusableListCell (Activity activity ) {
638
640
LinearLayout view = new LinearLayout (activity );
639
641
TextView textView = new TextView (activity );
640
642
textView .setId (android .R .id .text1 );
0 commit comments