Skip to content

Commit 1458233

Browse files
committed
Add setup method to DataHandleTest
This allows subclasses to modify testing parameters, first usecase is checkLength, which fails for compressed handles, as the handdle can have a different length than the content.
1 parent 23bc71e commit 1458233

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/test/java/org/scijava/io/DataHandleTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ public abstract class DataHandleTest {
5454
9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, -128, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, //
5555
125, 127, -127, -125, -3, -2, -1 };
5656

57+
/**
58+
* If the handle's length is checked during {@link #checkReads(DataHandle)},
59+
* can be changed by subclasses (e.g. when processing compressed handles with
60+
* unknown length);
61+
*/
62+
protected boolean checkLength = true;
63+
5764
// -- Test methods --
5865

5966
@Test
@@ -68,11 +75,16 @@ public void testDataHandle() throws IOException {
6875
{
6976
assertEquals(getExpectedHandleType(), handle.getClass());
7077

78+
setup();
7179
checkReads(handle);
7280
checkWrites(handle);
7381
}
7482
}
7583

84+
protected void setup() {
85+
// Subclasses can perform optional setup tasks here
86+
}
87+
7688
// -- DataHandleTest methods --
7789

7890
public abstract Class<? extends DataHandle<?>> getExpectedHandleType();
@@ -90,7 +102,7 @@ protected <L extends Location> void checkReads(final DataHandle<L> handle)
90102
throws IOException
91103
{
92104
assertEquals(0, handle.offset());
93-
assertEquals(BYTES.length, handle.length());
105+
if (checkLength) assertEquals(BYTES.length, handle.length());
94106
assertEquals("UTF-8", handle.getEncoding());
95107
assertEquals(BytesOrder.BIG_ENDIAN, handle.getOrder());
96108
assertEquals(false, handle.isLittleEndian());

0 commit comments

Comments
 (0)