Skip to content

Commit 050cb3e

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 3276f03 commit 050cb3e

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
@@ -57,6 +57,13 @@ public abstract class DataHandleTest {
5757
9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, -128, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, //
5858
125, 127, -127, -125, -3, -2, -1 };
5959

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

6269
@Test
@@ -71,11 +78,16 @@ public void testDataHandle() throws IOException {
7178
{
7279
assertEquals(getExpectedHandleType(), handle.getClass());
7380

81+
setup();
7482
checkReads(handle);
7583
checkWrites(handle);
7684
}
7785
}
7886

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

8193
public abstract Class<? extends DataHandle<?>> getExpectedHandleType();
@@ -93,7 +105,7 @@ protected <L extends Location> void checkReads(final DataHandle<L> handle)
93105
throws IOException
94106
{
95107
assertEquals(0, handle.offset());
96-
assertEquals(BYTES.length, handle.length());
108+
if (checkLength) assertEquals(BYTES.length, handle.length());
97109
assertEquals("UTF-8", handle.getEncoding());
98110
assertEquals(ByteOrder.BIG_ENDIAN, handle.getOrder());
99111
assertEquals(false, handle.isLittleEndian());

0 commit comments

Comments
 (0)