Skip to content

Instantly share code, notes, and snippets.

@strazzere
Created September 29, 2015 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strazzere/93fd9e4d6017075ccda3 to your computer and use it in GitHub Desktop.
Save strazzere/93fd9e4d6017075ccda3 to your computer and use it in GitHub Desktop.
woof, that unit test
@Override
public void setUp() throws Exception {
super.setUp();
mockReader = mock(IntReader.class);
// Mock the string section data
when(mockReader.readInt()).thenReturn(
7 * 4, // size
0x02, // string count
0x00, // style count
0x00, // string chunk flags
0x24, // string pool offset
// string pool
0x00, // item 1 offset
0x08, // item 2 offset
0x66696404, // item 1 data
0x66, // item 1 data
0x6D697403); // item 2 data
mockChunkType = mock(ChunkType.class);
when(mockChunkType.getIntType()).thenReturn(ChunkType.STRING_SECTION.getIntType());
underTest = new StringSection(mockChunkType, mockReader);
}
public void testToBytes() throws Exception {
byte[] expected = {
// STRING_SECTION
(byte) 0x01, (byte) 0x00, (byte) 0x1C, (byte) 0x00,
// size
(byte) (7 * 4), (byte) 0x00, (byte) 0x00, (byte) 0x00,
// string count
(byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
// TODO : Really should test this when I get a good sample
// style count
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
// string chunk flags
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
// string pool offset
(byte) 0x24, (byte) 0x00, (byte) 0x00, (byte) 0x00,
// style pool offset
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
// string pool offsets - item 1
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
// string pool offsets - item 2
(byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00,
// string data - item 1
// len(diff) d i f
(byte) 0x04, (byte) 0x64, (byte) 0x69, (byte) 0x66,
// f (buffer ----------------------------)
(byte) 0x66, (byte) 0x00, (byte) 0x00, (byte) 0x00,
// string data - item 2
// len(tim) t i m
(byte) 0x03, (byte) 0x74, (byte) 0x69, (byte) 0x6d
};
byte[] actual = underTest.toBytes();
Assert.assertArrayEquals(expected, actual);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment