Skip to content

Commit 6a92722

Browse files
committed
fix: ParseCountingUriHttpBodyTest.testWriteToWithNullOutput
1 parent 66d7fee commit 6a92722

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

parse/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ android {
1818
includeAndroidResources = true
1919

2020
all {
21+
jvmArgs '--add-opens=java.base/java.io=ALL-UNNAMED'
2122
// Configure JaCoCo options
2223
jacoco {
2324
includeNoLocationClasses = true

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

+28-4
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,53 @@
1212
import static org.junit.Assert.assertTrue;
1313
import static org.junit.Assert.fail;
1414

15+
import android.content.Context;
1516
import android.net.Uri;
17+
import androidx.test.platform.app.InstrumentationRegistry;
1618
import java.io.ByteArrayOutputStream;
1719
import java.io.File;
1820
import java.io.FileWriter;
1921
import java.io.IOException;
2022
import java.util.Arrays;
23+
import java.util.UUID;
2124
import java.util.concurrent.Semaphore;
2225
import java.util.concurrent.TimeUnit;
26+
import org.junit.After;
27+
import org.junit.Before;
2328
import org.junit.Rule;
2429
import org.junit.Test;
2530
import org.junit.rules.TemporaryFolder;
31+
import org.junit.runner.RunWith;
32+
import org.robolectric.RobolectricTestRunner;
2633

34+
@RunWith(RobolectricTestRunner.class)
2735
public class ParseCountingUriHttpBodyTest {
2836

2937
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
3038

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+
3154
private static String getData() {
3255
char[] chars = new char[64 << 14]; // 1MB
3356
Arrays.fill(chars, '1');
3457
return new String(chars);
3558
}
3659

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);
3962
FileWriter writer = new FileWriter(file);
4063
writer.write(getData());
4164
writer.close();
@@ -49,7 +72,7 @@ public void testWriteTo() throws Exception {
4972

5073
ParseCountingUriHttpBody body =
5174
new ParseCountingUriHttpBody(
52-
makeTestUri(temporaryFolder.getRoot()),
75+
makeTestUri(temporaryFolder.getRoot(), UUID.randomUUID().toString()),
5376
new ProgressCallback() {
5477
Integer maxProgressSoFar = 0;
5578

@@ -84,7 +107,8 @@ public void done(Integer percentDone) {
84107
@Test(expected = IllegalArgumentException.class)
85108
public void testWriteToWithNullOutput() throws Exception {
86109
ParseCountingUriHttpBody body =
87-
new ParseCountingUriHttpBody(makeTestUri(temporaryFolder.getRoot()), null);
110+
new ParseCountingUriHttpBody(
111+
makeTestUri(temporaryFolder.getRoot(), UUID.randomUUID().toString()), null);
88112
body.writeTo(null);
89113
}
90114
}

0 commit comments

Comments
 (0)