Skip to content

Commit 6e78557

Browse files
gab1onectrueden
authored andcommittedAug 31, 2017
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 528d096 commit 6e78557

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
 

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public abstract class DataHandleTest {
5858
9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, -128, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, //
5959
125, 127, -127, -125, -3, -2, -1 };
6060

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

6370
@Test
@@ -72,11 +79,16 @@ public void testDataHandle() throws IOException {
7279
{
7380
assertEquals(getExpectedHandleType(), handle.getClass());
7481

82+
setup();
7583
checkReads(handle);
7684
checkWrites(handle);
7785
}
7886
}
7987

88+
protected void setup() {
89+
// Subclasses can perform optional setup tasks here
90+
}
91+
8092
// -- DataHandleTest methods --
8193

8294
public abstract Class<? extends DataHandle<?>> getExpectedHandleType();
@@ -94,7 +106,7 @@ protected <L extends Location> void checkReads(final DataHandle<L> handle)
94106
throws IOException
95107
{
96108
assertEquals(0, handle.offset());
97-
assertEquals(BYTES.length, handle.length());
109+
if (checkLength) assertEquals(BYTES.length, handle.length());
98110
assertEquals("UTF-8", handle.getEncoding());
99111
assertEquals(ByteOrder.BIG_ENDIAN, handle.getOrder());
100112
assertEquals(false, handle.isLittleEndian());

0 commit comments

Comments
 (0)