Skip to content

Commit 6865aec

Browse files
committed
fix: ParseCountingUriHttpBodyTest.makeTestUri and ParseCountingUriHttpBodyTest.testWriteToWithNullOutput
1 parent 541b46a commit 6865aec

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,49 @@
1111
import static org.junit.Assert.assertArrayEquals;
1212
import static org.junit.Assert.assertTrue;
1313
import static org.junit.Assert.fail;
14+
import static org.mockito.Mockito.mock;
15+
import static org.mockito.Mockito.when;
1416

17+
import android.content.Context;
1518
import android.net.Uri;
19+
import androidx.test.platform.app.InstrumentationRegistry;
1620
import java.io.ByteArrayOutputStream;
1721
import java.io.File;
1822
import java.io.FileWriter;
1923
import java.io.IOException;
2024
import java.util.Arrays;
25+
import java.util.UUID;
2126
import java.util.concurrent.Semaphore;
2227
import java.util.concurrent.TimeUnit;
28+
import org.junit.Before;
2329
import org.junit.Rule;
2430
import org.junit.Test;
2531
import org.junit.rules.TemporaryFolder;
32+
import org.junit.runner.RunWith;
33+
import org.robolectric.RobolectricTestRunner;
2634

27-
public class ParseCountingUriHttpBodyTest {
35+
@RunWith(RobolectricTestRunner.class)
36+
public class ParseCountingUriHttpBodyTest extends ResetPluginsParseTest {
2837

2938
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
3039

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+
3149
private static String getData() {
3250
char[] chars = new char[64 << 14]; // 1MB
3351
Arrays.fill(chars, '1');
3452
return new String(chars);
3553
}
3654

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);
3957
FileWriter writer = new FileWriter(file);
4058
writer.write(getData());
4159
writer.close();
@@ -49,7 +67,7 @@ public void testWriteTo() throws Exception {
4967

5068
ParseCountingUriHttpBody body =
5169
new ParseCountingUriHttpBody(
52-
makeTestUri(temporaryFolder.getRoot()),
70+
makeTestUri(temporaryFolder.getRoot(), UUID.randomUUID().toString()),
5371
new ProgressCallback() {
5472
Integer maxProgressSoFar = 0;
5573

@@ -84,7 +102,8 @@ public void done(Integer percentDone) {
84102
@Test(expected = IllegalArgumentException.class)
85103
public void testWriteToWithNullOutput() throws Exception {
86104
ParseCountingUriHttpBody body =
87-
new ParseCountingUriHttpBody(makeTestUri(temporaryFolder.getRoot()), null);
105+
new ParseCountingUriHttpBody(
106+
makeTestUri(temporaryFolder.getRoot(), UUID.randomUUID().toString()), null);
88107
body.writeTo(null);
89108
}
90109
}

0 commit comments

Comments
 (0)