Skip to content

Commit

Permalink
fix: ParseCountingUriHttpBodyTest.makeTestUri and ParseCountingUriHtt…
Browse files Browse the repository at this point in the history
…pBodyTest.testWriteToWithNullOutput
  • Loading branch information
abubkr-hago committed Aug 19, 2024
1 parent 541b46a commit 6865aec
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions parse/src/test/java/com/parse/ParseCountingUriHttpBodyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 6865aec

Please sign in to comment.