Parser { protected byte parseByteField(int length) { if (length == 0) { throw new ParserException("Cannot parse byte of size 0"); } if (length > 1) { LOGGER.warn("Parsing byte[] field into a byte of size >1"); } return (byte) ArrayConverter.bytesToInt(parseByteArrayField(length)); } Parser(int startposition, byte[] array); int getPointer(); void setPointer(int pointer); int getStartPoint(); abstract T parse();  }
@Test public void testParseByteField() { byte[] result = parser.parseByteArrayField(1); assertArrayEquals(result, new byte[] { 0 }); result = parser.parseByteArrayField(2); assertArrayEquals(result, new byte[] { 1, 2 }); result = middleParser.parseByteArrayField(1); assertArrayEquals(result, new byte[] { 3 }); result = middleParser.parseByteArrayField(2); assertArrayEquals(result, new byte[] { 4, 5 }); }
@Test public void testParseSingleByteField() { byte result = parser.parseByteField(1); assertEquals(result, 0); result = middleParser.parseByteField(1); assertEquals(result, 3); }
@Test(expected = ParserException.class) public void testParseSingleByteFieldNegative() { parser.parseByteField(-123); }
@Test(expected = ParserException.class) public void testParseSingleByteFieldZero() { assertNull(parser.parseByteField(0)); }