From c56df67d2a1b1a90104f7a5881cc6398b5c278c6 Mon Sep 17 00:00:00 2001 From: Gabriel Einsdorf Date: Tue, 16 Oct 2018 16:56:10 +0200 Subject: [PATCH] DataHandleTest: allow for handles with unknown length Some handles don't know their length and instead return -1, this commit adds an option to the length check to assure this. --- src/test/java/org/scijava/io/handle/DataHandleTest.java | 7 ++++--- .../org/scijava/io/handle/ReadBufferDataHandleTest.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/scijava/io/handle/DataHandleTest.java b/src/test/java/org/scijava/io/handle/DataHandleTest.java index 7c38e3e1a..859456ebe 100644 --- a/src/test/java/org/scijava/io/handle/DataHandleTest.java +++ b/src/test/java/org/scijava/io/handle/DataHandleTest.java @@ -113,7 +113,7 @@ public void testEndianesSettings() throws IOException { @Test public void testReading() throws IOException { try (final DataHandle handle = createHandle()) { - checkBasicReadMethods(handle); + checkBasicReadMethods(handle, true); checkEndiannessReading(handle); } } @@ -168,13 +168,14 @@ public void populateData(final OutputStream out) throws IOException { * Checks basic byte reading methods. * * @param handle the handle to test + * @param lengthKnown whether the length of the handle is know * @throws IOException */ public void checkBasicReadMethods( - final DataHandle handle) throws IOException + final DataHandle handle, boolean lengthKnown) throws IOException { assertEquals(0, handle.offset()); - assertEquals(BYTES.length, handle.length()); + assertEquals(lengthKnown ? BYTES.length : -1, handle.length()); assertEquals("UTF-8", handle.getEncoding()); // test read() diff --git a/src/test/java/org/scijava/io/handle/ReadBufferDataHandleTest.java b/src/test/java/org/scijava/io/handle/ReadBufferDataHandleTest.java index e7cb332f2..99d04e3fb 100644 --- a/src/test/java/org/scijava/io/handle/ReadBufferDataHandleTest.java +++ b/src/test/java/org/scijava/io/handle/ReadBufferDataHandleTest.java @@ -64,7 +64,7 @@ public void testSmallBuffer() throws IOException { new ReadBufferDataHandle(handle, 5)) { // check with small buffersize - checkBasicReadMethods(bufferedHandle); + checkBasicReadMethods(bufferedHandle, true); checkEndiannessReading(bufferedHandle); } }