Serializer { protected final void appendInt(int i, int length) { byte[] bytes = ArrayConverter.intToBytes(i, length); int reconvertedInt = ArrayConverter.bytesToInt(bytes); if (reconvertedInt != i) { LOGGER.warn("Int \"" + i + "\" is too long to write in field of size " + length + ". Only using last " + length + " bytes."); } appendBytes(ArrayConverter.intToBytes(i, length)); } Serializer(); final byte[] serialize(); ByteArrayOutputStream getOutputStream();  }
@Test public void testAppendInt() { serializer.appendInt(257, 2); byte[] result = serializer.getAlreadySerialized(); assertArrayEquals(result, new byte[] { 1, 1, }); serializer = new SerializerImpl(); serializer.appendInt(257, 1); result = serializer.getAlreadySerialized(); assertArrayEquals(result, new byte[] { 1, }); }