Skip to content

Commit

Permalink
Add setup method to DataHandleTest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gab1one authored and ctrueden committed Aug 31, 2017
1 parent 528d096 commit 6e78557
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/test/java/org/scijava/io/handle/DataHandleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public abstract class DataHandleTest {
9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, -128, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, //
125, 127, -127, -125, -3, -2, -1 };

/**
* If the handle's length is checked during {@link #checkReads(DataHandle)},
* can be changed by subclasses (e.g. when processing compressed handles with
* unknown length);
*/
protected boolean checkLength = true;

// -- Test methods --

@Test
Expand All @@ -72,11 +79,16 @@ public void testDataHandle() throws IOException {
{
assertEquals(getExpectedHandleType(), handle.getClass());

setup();
checkReads(handle);
checkWrites(handle);
}
}

protected void setup() {
// Subclasses can perform optional setup tasks here
}

// -- DataHandleTest methods --

public abstract Class<? extends DataHandle<?>> getExpectedHandleType();
Expand All @@ -94,7 +106,7 @@ protected <L extends Location> void checkReads(final DataHandle<L> handle)
throws IOException
{
assertEquals(0, handle.offset());
assertEquals(BYTES.length, handle.length());
if (checkLength) assertEquals(BYTES.length, handle.length());
assertEquals("UTF-8", handle.getEncoding());
assertEquals(ByteOrder.BIG_ENDIAN, handle.getOrder());
assertEquals(false, handle.isLittleEndian());
Expand Down

0 comments on commit 6e78557

Please sign in to comment.