Skip to content

Commit c56df67

Browse files
committed
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.
1 parent 2f54eed commit c56df67

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Diff for: src/test/java/org/scijava/io/handle/DataHandleTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void testEndianesSettings() throws IOException {
113113
@Test
114114
public void testReading() throws IOException {
115115
try (final DataHandle<? extends Location> handle = createHandle()) {
116-
checkBasicReadMethods(handle);
116+
checkBasicReadMethods(handle, true);
117117
checkEndiannessReading(handle);
118118
}
119119
}
@@ -168,13 +168,14 @@ public void populateData(final OutputStream out) throws IOException {
168168
* Checks basic byte reading methods.
169169
*
170170
* @param handle the handle to test
171+
* @param lengthKnown whether the length of the handle is know
171172
* @throws IOException
172173
*/
173174
public <L extends Location> void checkBasicReadMethods(
174-
final DataHandle<L> handle) throws IOException
175+
final DataHandle<L> handle, boolean lengthKnown) throws IOException
175176
{
176177
assertEquals(0, handle.offset());
177-
assertEquals(BYTES.length, handle.length());
178+
assertEquals(lengthKnown ? BYTES.length : -1, handle.length());
178179
assertEquals("UTF-8", handle.getEncoding());
179180

180181
// test read()

Diff for: src/test/java/org/scijava/io/handle/ReadBufferDataHandleTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testSmallBuffer() throws IOException {
6464
new ReadBufferDataHandle(handle, 5))
6565
{
6666
// check with small buffersize
67-
checkBasicReadMethods(bufferedHandle);
67+
checkBasicReadMethods(bufferedHandle, true);
6868
checkEndiannessReading(bufferedHandle);
6969
}
7070
}

0 commit comments

Comments
 (0)