12
12
import static org .junit .Assert .assertTrue ;
13
13
import static org .junit .Assert .fail ;
14
14
15
+ import android .content .Context ;
15
16
import android .net .Uri ;
17
+ import androidx .test .platform .app .InstrumentationRegistry ;
16
18
import java .io .ByteArrayOutputStream ;
17
19
import java .io .File ;
18
20
import java .io .FileWriter ;
19
21
import java .io .IOException ;
20
22
import java .util .Arrays ;
23
+ import java .util .UUID ;
21
24
import java .util .concurrent .Semaphore ;
22
25
import java .util .concurrent .TimeUnit ;
26
+ import org .junit .After ;
27
+ import org .junit .Before ;
23
28
import org .junit .Rule ;
24
29
import org .junit .Test ;
25
30
import org .junit .rules .TemporaryFolder ;
31
+ import org .junit .runner .RunWith ;
32
+ import org .robolectric .RobolectricTestRunner ;
26
33
34
+ @ RunWith (RobolectricTestRunner .class )
27
35
public class ParseCountingUriHttpBodyTest {
28
36
29
37
@ Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder ();
30
38
39
+ @ Before
40
+ public void setup () {
41
+ Context context = InstrumentationRegistry .getInstrumentation ().getTargetContext ();
42
+ Parse .initialize (
43
+ new Parse .Configuration .Builder (context )
44
+ .server ("http://localhost:1337/parse" )
45
+ .applicationId ("parse" )
46
+ .build ());
47
+ }
48
+
49
+ @ After
50
+ public void tearDown () {
51
+ Parse .destroy ();
52
+ }
53
+
31
54
private static String getData () {
32
55
char [] chars = new char [64 << 14 ]; // 1MB
33
56
Arrays .fill (chars , '1' );
34
57
return new String (chars );
35
58
}
36
59
37
- private static Uri makeTestUri (File root ) throws IOException {
38
- File file = new File (root , "test" );
60
+ private static Uri makeTestUri (File root , String name ) throws IOException {
61
+ File file = new File (root , name );
39
62
FileWriter writer = new FileWriter (file );
40
63
writer .write (getData ());
41
64
writer .close ();
@@ -49,7 +72,7 @@ public void testWriteTo() throws Exception {
49
72
50
73
ParseCountingUriHttpBody body =
51
74
new ParseCountingUriHttpBody (
52
- makeTestUri (temporaryFolder .getRoot ()),
75
+ makeTestUri (temporaryFolder .getRoot (), UUID . randomUUID (). toString () ),
53
76
new ProgressCallback () {
54
77
Integer maxProgressSoFar = 0 ;
55
78
@@ -84,7 +107,8 @@ public void done(Integer percentDone) {
84
107
@ Test (expected = IllegalArgumentException .class )
85
108
public void testWriteToWithNullOutput () throws Exception {
86
109
ParseCountingUriHttpBody body =
87
- new ParseCountingUriHttpBody (makeTestUri (temporaryFolder .getRoot ()), null );
110
+ new ParseCountingUriHttpBody (
111
+ makeTestUri (temporaryFolder .getRoot (), UUID .randomUUID ().toString ()), null );
88
112
body .writeTo (null );
89
113
}
90
114
}
0 commit comments