11
11
import static org .junit .Assert .assertArrayEquals ;
12
12
import static org .junit .Assert .assertTrue ;
13
13
import static org .junit .Assert .fail ;
14
+ import static org .mockito .Mockito .mock ;
15
+ import static org .mockito .Mockito .when ;
14
16
17
+ import android .content .Context ;
15
18
import android .net .Uri ;
19
+ import androidx .test .platform .app .InstrumentationRegistry ;
16
20
import java .io .ByteArrayOutputStream ;
17
21
import java .io .File ;
18
22
import java .io .FileWriter ;
19
23
import java .io .IOException ;
20
24
import java .util .Arrays ;
25
+ import java .util .UUID ;
21
26
import java .util .concurrent .Semaphore ;
22
27
import java .util .concurrent .TimeUnit ;
28
+ import org .junit .Before ;
23
29
import org .junit .Rule ;
24
30
import org .junit .Test ;
25
31
import org .junit .rules .TemporaryFolder ;
32
+ import org .junit .runner .RunWith ;
33
+ import org .robolectric .RobolectricTestRunner ;
26
34
27
- public class ParseCountingUriHttpBodyTest {
35
+ @ RunWith (RobolectricTestRunner .class )
36
+ public class ParseCountingUriHttpBodyTest extends ResetPluginsParseTest {
28
37
29
38
@ Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder ();
30
39
40
+ @ Before
41
+ public void setup () throws Exception {
42
+ super .setUp ();
43
+ Context context = InstrumentationRegistry .getInstrumentation ().getTargetContext ();
44
+ ParsePlugins plugins = mock (ParsePlugins .class );
45
+ when (plugins .applicationContext ()).thenReturn (context );
46
+ ParsePlugins .set (plugins );
47
+ }
48
+
31
49
private static String getData () {
32
50
char [] chars = new char [64 << 14 ]; // 1MB
33
51
Arrays .fill (chars , '1' );
34
52
return new String (chars );
35
53
}
36
54
37
- private static Uri makeTestUri (File root ) throws IOException {
38
- File file = new File (root , "test" );
55
+ private static Uri makeTestUri (File root , String filename ) throws IOException {
56
+ File file = new File (root , filename );
39
57
FileWriter writer = new FileWriter (file );
40
58
writer .write (getData ());
41
59
writer .close ();
@@ -49,7 +67,7 @@ public void testWriteTo() throws Exception {
49
67
50
68
ParseCountingUriHttpBody body =
51
69
new ParseCountingUriHttpBody (
52
- makeTestUri (temporaryFolder .getRoot ()),
70
+ makeTestUri (temporaryFolder .getRoot (), UUID . randomUUID (). toString () ),
53
71
new ProgressCallback () {
54
72
Integer maxProgressSoFar = 0 ;
55
73
@@ -84,7 +102,8 @@ public void done(Integer percentDone) {
84
102
@ Test (expected = IllegalArgumentException .class )
85
103
public void testWriteToWithNullOutput () throws Exception {
86
104
ParseCountingUriHttpBody body =
87
- new ParseCountingUriHttpBody (makeTestUri (temporaryFolder .getRoot ()), null );
105
+ new ParseCountingUriHttpBody (
106
+ makeTestUri (temporaryFolder .getRoot (), UUID .randomUUID ().toString ()), null );
88
107
body .writeTo (null );
89
108
}
90
109
}
0 commit comments