2121
2222package com .parse ;
2323
24+ import android .app .Activity ;
2425import android .database .DataSetObserver ;
26+ import android .test .ActivityInstrumentationTestCase2 ;
2527import android .view .View ;
2628import android .widget .LinearLayout ;
2729import android .widget .ListView ;
4951import static org .mockito .Mockito .mock ;
5052import static org .mockito .Mockito .when ;
5153
52- public class ParseQueryAdapterTest extends BaseActivityInstrumentationTestCase2 <TestActivity > {
54+ public class ParseQueryAdapterTest extends ActivityInstrumentationTestCase2 <TestActivity > {
5355
5456 @ ParseClassName ("Thing" )
5557 public static class Thing extends ParseObject {
@@ -69,7 +71,7 @@ public ParseQueryAdapterTest() {
6971 public void setUp () throws Exception {
7072 super .setUp ();
7173
72- listView = new ListView (activity );
74+ listView = new ListView (getActivity () );
7375 savedThings = new ArrayList <>();
7476 totalThings = 10 ;
7577
@@ -141,7 +143,7 @@ public void tearDown() throws Exception {
141143 }
142144
143145 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 );
145147 final Semaphore done = new Semaphore (0 );
146148 adapter .addOnQueryLoadListener (new OnQueryLoadListener <Thing >() {
147149 @ Override
@@ -164,7 +166,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
164166
165167 public void testLoadObjectsWithGenericParseObjects () throws Exception {
166168 final ParseQueryAdapter <ParseObject > adapter =
167- new ParseQueryAdapter <>(activity , Thing .class );
169+ new ParseQueryAdapter <>(getActivity () , Thing .class );
168170 final Semaphore done = new Semaphore (0 );
169171 adapter .addOnQueryLoadListener (new OnQueryLoadListener <ParseObject >() {
170172 @ Override
@@ -186,19 +188,19 @@ public void onLoaded(List<ParseObject> objects, Exception e) {
186188 }
187189
188190 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 );
191193 adapter .setTextKey ("name" );
192194
193- View view = adapter .getItemView (savedThings .get (0 ), buildReusableListCell (), listView );
195+ View view = adapter .getItemView (savedThings .get (0 ), buildReusableListCell (activity ), listView );
194196 TextView textView = (TextView ) view .findViewById (android .R .id .text1 );
195197
196198 assertEquals ("Thing 0" , textView .getText ());
197199 }
198200
199201 public void testGetItemViewWithCustomLayout () {
200202 ParseQueryAdapter <ParseObject > adapter =
201- new ParseQueryAdapter <>(activity , Thing .class , R .layout .view_item );
203+ new ParseQueryAdapter <>(getActivity () , Thing .class , R .layout .view_item );
202204 adapter .setTextKey ("name" );
203205
204206 View view = adapter .getItemView (savedThings .get (0 ), null , listView );
@@ -211,7 +213,7 @@ public void testGetItemViewWithCustomLayout() {
211213
212214 public void testGetItemViewWithNoTextKey () throws ParseException {
213215 ParseQueryAdapter <ParseObject > adapter =
214- new ParseQueryAdapter <>(activity , Thing .class );
216+ new ParseQueryAdapter <>(getActivity () , Thing .class );
215217
216218 View view = adapter .getItemView (savedThings .get (0 ), null , listView );
217219 TextView textView = (TextView ) view .findViewById (android .R .id .text1 );
@@ -221,7 +223,7 @@ public void testGetItemViewWithNoTextKey() throws ParseException {
221223 }
222224
223225 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 );
225227 final int pageSize = 4 ;
226228 adapter .setObjectsPerPage (pageSize );
227229 final Capture <Integer > timesThrough = new Capture <>(0 );
@@ -268,7 +270,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
268270 }
269271
270272 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 );
272274 final int pageSize = 5 ;
273275 adapter .setObjectsPerPage (pageSize );
274276 final Capture <Integer > timesThrough = new Capture <>(0 );
@@ -311,7 +313,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
311313 }
312314
313315 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 );
315317 final int pageSize = 5 ;
316318 adapter .setObjectsPerPage (pageSize );
317319 final Capture <Integer > timesThrough = new Capture <>(0 );
@@ -363,7 +365,7 @@ public void testLoadObjectsWithNoPagination() throws Exception {
363365 }
364366 totalThings += additional ;
365367
366- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , Thing .class );
368+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , Thing .class );
367369 adapter .setPaginationEnabled (false );
368370 final Semaphore done = new Semaphore (0 );
369371 adapter .addOnQueryLoadListener (new OnQueryLoadListener <Thing >() {
@@ -387,7 +389,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
387389 }
388390
389391 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 );
391393 final Semaphore done = new Semaphore (0 );
392394 final Capture <Integer > counter = new Capture <>(0 );
393395 adapter .addOnQueryLoadListener (new OnQueryLoadListener <Thing >() {
@@ -433,7 +435,7 @@ public ParseQuery<Thing> create() {
433435 }
434436 };
435437
436- final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(activity , factory );
438+ final ParseQueryAdapter <Thing > adapter = new ParseQueryAdapter <>(getActivity () , factory );
437439 final int pageSize = 5 ;
438440 adapter .setObjectsPerPage (pageSize );
439441 adapter .setPaginationEnabled (true );
@@ -497,7 +499,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
497499 }
498500
499501 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 );
501503 adapter .setObjectsPerPage (5 );
502504 final Capture <Boolean > flag = new Capture <>(false );
503505 final Semaphore done = new Semaphore (0 );
@@ -525,7 +527,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
525527 }
526528
527529 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 );
529531 final Semaphore done = new Semaphore (0 );
530532 adapter .addOnQueryLoadListener (new OnQueryLoadListener <Thing >() {
531533 @ Override
@@ -547,7 +549,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
547549 }
548550
549551 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 );
551553 final int pageSize = 4 ;
552554 adapter .setObjectsPerPage (pageSize );
553555 final Semaphore done = new Semaphore (0 );
@@ -578,7 +580,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
578580 public void testLoadObjectsWithOverrideSetPageOnQuery () throws Exception {
579581 final int arbitraryLimit = 3 ;
580582 final ParseQueryAdapter <Thing > adapter =
581- new ParseQueryAdapter <Thing >(activity , Thing .class ) {
583+ new ParseQueryAdapter <Thing >(getActivity () , Thing .class ) {
582584 @ Override
583585 public void setPageOnQuery (int page , ParseQuery <Thing > query ) {
584586 // Make sure that this method is being used + respected.
@@ -605,7 +607,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
605607 }
606608
607609 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 );
609611 final Capture <Boolean > flag = new Capture <>(false );
610612 // Make sure that the Adapter doesn't start trying to load objects until AFTER we set this flag
611613 // to true (= triggered by calling setAutoload, NOT registerDataSetObserver, if autoload is
@@ -634,7 +636,7 @@ public void onLoaded(List<Thing> objects, Exception e) {
634636 assertTrue (done .tryAcquire (10 , TimeUnit .SECONDS ));
635637 }
636638
637- private LinearLayout buildReusableListCell () {
639+ private static LinearLayout buildReusableListCell (Activity activity ) {
638640 LinearLayout view = new LinearLayout (activity );
639641 TextView textView = new TextView (activity );
640642 textView .setId (android .R .id .text1 );
0 commit comments