diff --git a/parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java b/parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java index 777851e5..404cdcea 100644 --- a/parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java +++ b/parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java @@ -11,31 +11,49 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import android.content.Context; import android.net.Uri; +import androidx.test.platform.app.InstrumentationRegistry; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; +import java.util.UUID; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; -public class ParseCountingUriHttpBodyTest { +@RunWith(RobolectricTestRunner.class) +public class ParseCountingUriHttpBodyTest extends ResetPluginsParseTest { @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before + public void setup() throws Exception { + super.setUp(); + Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); + ParsePlugins plugins = mock(ParsePlugins.class); + when(plugins.applicationContext()).thenReturn(context); + ParsePlugins.set(plugins); + } + private static String getData() { char[] chars = new char[64 << 14]; // 1MB Arrays.fill(chars, '1'); return new String(chars); } - private static Uri makeTestUri(File root) throws IOException { - File file = new File(root, "test"); + private static Uri makeTestUri(File root, String filename) throws IOException { + File file = new File(root, filename); FileWriter writer = new FileWriter(file); writer.write(getData()); writer.close(); @@ -49,7 +67,7 @@ public void testWriteTo() throws Exception { ParseCountingUriHttpBody body = new ParseCountingUriHttpBody( - makeTestUri(temporaryFolder.getRoot()), + makeTestUri(temporaryFolder.getRoot(), UUID.randomUUID().toString()), new ProgressCallback() { Integer maxProgressSoFar = 0; @@ -84,7 +102,8 @@ public void done(Integer percentDone) { @Test(expected = IllegalArgumentException.class) public void testWriteToWithNullOutput() throws Exception { ParseCountingUriHttpBody body = - new ParseCountingUriHttpBody(makeTestUri(temporaryFolder.getRoot()), null); + new ParseCountingUriHttpBody( + makeTestUri(temporaryFolder.getRoot(), UUID.randomUUID().toString()), null); body.writeTo(null); } }