From f99928796cd1449175c45388cf8ebb13a47c0050 Mon Sep 17 00:00:00 2001 From: arun Date: Tue, 13 Feb 2018 11:43:02 -0600 Subject: [PATCH] test for SegmentationPlanBoundedInputStream.java and UploadPayloadBoundedInputStream.java --- ...egmentationPlanBoundedInputStreamTest.java | 29 +++++++++++++ .../UploadPayloadBounderInputStreamTest.java | 41 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/test/java/org/javaswift/joss/instructions/SegmentationPlanBoundedInputStreamTest.java create mode 100644 src/test/java/org/javaswift/joss/instructions/UploadPayloadBounderInputStreamTest.java diff --git a/src/test/java/org/javaswift/joss/instructions/SegmentationPlanBoundedInputStreamTest.java b/src/test/java/org/javaswift/joss/instructions/SegmentationPlanBoundedInputStreamTest.java new file mode 100644 index 00000000..3fa46b32 --- /dev/null +++ b/src/test/java/org/javaswift/joss/instructions/SegmentationPlanBoundedInputStreamTest.java @@ -0,0 +1,29 @@ +package org.javaswift.joss.instructions; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static junit.framework.Assert.assertEquals; + +public class SegmentationPlanBoundedInputStreamTest extends SegmentationPlanTestBase { + + @Test + public void getSegmentNumber() throws IOException { + String text = "Some text that needs to be read as several segments which we patch together again and compare to the original"; + InputStream inputStream = IOUtils.toInputStream(text); + SegmentationPlan plan = new SegmentationPlanBoundedInputStream(inputStream, text.length(), 10L); + assertEquals(Long.valueOf(0L), plan.getSegmentNumber()); + } + + @Test + public void readItAll() throws IOException { + String text = "Some text that needs to be read as several segments which we patch together again and compare to the original"; + InputStream inputStream = IOUtils.toInputStream(text); + SegmentationPlan plan = new SegmentationPlanBoundedInputStream(inputStream, text.length(), 10L); + assertTextEquals(plan, text); + plan.close(); + } +} diff --git a/src/test/java/org/javaswift/joss/instructions/UploadPayloadBounderInputStreamTest.java b/src/test/java/org/javaswift/joss/instructions/UploadPayloadBounderInputStreamTest.java new file mode 100644 index 00000000..1e91ec20 --- /dev/null +++ b/src/test/java/org/javaswift/joss/instructions/UploadPayloadBounderInputStreamTest.java @@ -0,0 +1,41 @@ +package org.javaswift.joss.instructions; + +import mockit.Injectable; +import org.apache.commons.io.IOUtils; +import org.junit.Test; + +import java.io.*; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +public class UploadPayloadBounderInputStreamTest extends SegmentationPlanTestBase { + + @Test + public void mustBeSegmented(@Injectable final InputStream inputStream) { + checkForRequiredSegmentation(inputStream, 12L, 9L, true); + } + + @Test + public void mustNotBeSegmented(@Injectable final InputStream inputStream) { + checkForRequiredSegmentation(inputStream, 9L, 12L, false); + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + @Test + public void getSegmentationPlan() throws IOException { + String text = "Some text that needs to be read as several segments which we patch together again and compare to the original"; + InputStream inputStream = IOUtils.toInputStream(text); + UploadPayload payload = new UploadPayloadBoundedInputStream(inputStream, text.length()); + assertNotNull(payload.getSegmentationPlan(10L)); + } + + protected UploadPayload createUploadPayload(final InputStream inputStream, final Long length) { + return new UploadPayloadBoundedInputStream(inputStream, length); + } + + protected void checkForRequiredSegmentation(InputStream inputStream, Long length, Long segmentationSize, boolean expectSegmentation) { + UploadPayload payload = createUploadPayload(inputStream, length); + assertEquals(expectSegmentation, payload.mustBeSegmented(segmentationSize)); + } +}