Parser { protected int parseIntField(int length) { if (length == 0) { throw new ParserException("Cannot parse int of size 0"); } return ArrayConverter.bytesToInt(parseByteArrayField(length)); } Parser(int startposition, byte[] array); int getPointer(); void setPointer(int pointer); int getStartPoint(); abstract T parse();  }
@Test public void testParseIntField() { int result = parser.parseIntField(1); assertTrue(result == 0); result = parser.parseIntField(2); assertTrue(result == 0x0102); result = middleParser.parseIntField(1); assertTrue(result == 3); result = middleParser.parseIntField(2); assertTrue(result == 0x0405); }
@Test(expected = ParserException.class) public void testParseIntFieldNegative() { parser.parseIntField(-123); }
@Test(expected = ParserException.class) public void testParseIntFieldZero() { parser.parseIntField(0); }