14
14
15
15
package com .firebase .ui .database ;
16
16
17
- import android .test .AndroidTestCase ;
17
+ import android .support .test .runner .AndroidJUnit4 ;
18
+ import android .test .InstrumentationTestCase ;
19
+ import android .test .suitebuilder .annotation .SmallTest ;
18
20
19
21
import com .google .firebase .FirebaseApp ;
20
22
import com .google .firebase .database .DatabaseError ;
27
29
import org .junit .After ;
28
30
import org .junit .Before ;
29
31
import org .junit .Test ;
32
+ import org .junit .runner .RunWith ;
30
33
31
34
import java .util .concurrent .Callable ;
32
35
import java .util .concurrent .TimeUnit ;
33
36
34
- public class FirebaseArrayTest extends AndroidTestCase {
37
+ @ RunWith (AndroidJUnit4 .class )
38
+ @ SmallTest
39
+ public class FirebaseArrayTest extends InstrumentationTestCase {
40
+
41
+ private static final int TIMEOUT = 5000 ;
42
+
35
43
private DatabaseReference mRef ;
36
44
private FirebaseArray mArray ;
37
45
38
46
@ Before
39
47
public void setUp () throws Exception {
40
- FirebaseApp app = ApplicationTest .getAppInstance (getContext ());
48
+ FirebaseApp app = ApplicationTest .getAppInstance (getInstrumentation (). getContext ());
41
49
mRef = FirebaseDatabase .getInstance (app ).getReference ().child ("firebasearray" );
42
50
mArray = new FirebaseArray (mRef );
43
51
mRef .removeValue ();
@@ -56,8 +64,13 @@ public Boolean call() throws Exception {
56
64
57
65
@ After
58
66
public void tearDown () throws Exception {
59
- mArray .cleanup ();
60
- mRef .removeValue ();
67
+ if (mRef != null ) {
68
+ mRef .getRoot ().removeValue ();
69
+ }
70
+
71
+ if (mArray != null ) {
72
+ mArray .cleanup ();
73
+ }
61
74
}
62
75
63
76
@ Test
@@ -155,7 +168,7 @@ public void onCancelled(DatabaseError databaseError) {
155
168
task .run ();
156
169
boolean isDone = false ;
157
170
long startedAt = System .currentTimeMillis ();
158
- while (!isDone && System .currentTimeMillis () - startedAt < 5000 ) {
171
+ while (!isDone && System .currentTimeMillis () - startedAt < TIMEOUT ) {
159
172
semaphore .tryAcquire (1 , TimeUnit .SECONDS );
160
173
try {
161
174
isDone = done .call ();
0 commit comments