X-Git-Url: https://git.pterodactylus.net/?p=jFCPlib.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2FTempInputStreamTest.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2FTempInputStreamTest.java;h=e3f24426fbc0ddaafd3f466f877c4410e69247e3;hp=4e3646b682936ede55c8a08e4b964abf886e12eb;hb=43c9b2ad0e27b4b0bd90c2189f7791f8d8ae5a1a;hpb=20ccf2bb5c5da6c74706b93eb32b4a31a47f0882 diff --git a/src/test/java/net/pterodactylus/fcp/TempInputStreamTest.java b/src/test/java/net/pterodactylus/fcp/TempInputStreamTest.java index 4e3646b..e3f2442 100644 --- a/src/test/java/net/pterodactylus/fcp/TempInputStreamTest.java +++ b/src/test/java/net/pterodactylus/fcp/TempInputStreamTest.java @@ -1,54 +1,54 @@ -package net.pterodactylus.fcp; - -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertArrayEquals; - - -public class TempInputStreamTest { - - private byte[] prepareArrayOfNBytes(int n) { - byte[] data = new byte[n]; - for (int i = 0; i < n; ++i) { - data[i] = (byte)i; - } - return data; - } - - private void checkTempInputStreamStoresPartOfAnotherStream(int length, int maxMemoryLength) throws IOException { - byte[] originalData = prepareArrayOfNBytes(length + 1); - InputStream anotherStream = new ByteArrayInputStream(originalData); - FcpUtils.TempInputStream cut = new FcpUtils.TempInputStream(anotherStream, length, maxMemoryLength); - - // check length bytes are read from anotherStream and are accessible from cut - byte[] buffer = new byte[length]; - int n = cut.read(buffer); - assertThat(n, is(length)); - assertArrayEquals(Arrays.copyOf(originalData, length), buffer); - assertThat(cut.read(), is(-1)); // check end of cut stream - - // check the rest of data in anotherStream is still there - n = anotherStream.read(buffer); - assertThat(n, is(1)); - assertThat(buffer[0], is(originalData[originalData.length - 1])); - assertThat(anotherStream.read(), is(-1)); // check end of another stream - } - - @Test - public void tempInputStreamShouldCorrectlyStorePartOfAnotherStreamInMemory() throws IOException { - checkTempInputStreamStoresPartOfAnotherStream(1, 1); - } - - @Test - public void tempInputStreamShouldCorrectlyStorePartOfAnotherStreamInFile() throws IOException { - checkTempInputStreamStoresPartOfAnotherStream(2, 1); - } - -} +package net.pterodactylus.fcp; + +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertArrayEquals; + + +public class TempInputStreamTest { + + private byte[] prepareArrayOfNBytes(int n) { + byte[] data = new byte[n]; + for (int i = 0; i < n; ++i) { + data[i] = (byte)i; + } + return data; + } + + private void checkTempInputStreamStoresPartOfAnotherStream(int length, int maxMemoryLength) throws IOException { + byte[] originalData = prepareArrayOfNBytes(length + 1); + InputStream anotherStream = new ByteArrayInputStream(originalData); + FcpUtils.TempInputStream cut = new FcpUtils.TempInputStream(anotherStream, length, maxMemoryLength); + + // check length bytes are read from anotherStream and are accessible from cut + byte[] buffer = new byte[length]; + int n = cut.read(buffer); + assertThat(n, is(length)); + assertArrayEquals(Arrays.copyOf(originalData, length), buffer); + assertThat(cut.read(), is(-1)); // check end of cut stream + + // check the rest of data in anotherStream is still there + n = anotherStream.read(buffer); + assertThat(n, is(1)); + assertThat(buffer[0], is(originalData[originalData.length - 1])); + assertThat(anotherStream.read(), is(-1)); // check end of another stream + } + + @Test + public void tempInputStreamShouldCorrectlyStorePartOfAnotherStreamInMemory() throws IOException { + checkTempInputStreamStoresPartOfAnotherStream(1, 1); + } + + @Test + public void tempInputStreamShouldCorrectlyStorePartOfAnotherStreamInFile() throws IOException { + checkTempInputStreamStoresPartOfAnotherStream(2, 1); + } + +}