@Test public void decodesTheConstantValueAsIs() throws IOException { int initialPosition = bytesIn.getPosition(); bytesIn.setBuffer(encoded); it.decodeConstant(in); assertThat(bytesIn.getPosition(), is(initialPosition + encoded.length)); }
@Test public void decodesTheEmptyConstant() throws IOException { it = new ConstantType(""); int initialPosition = bytesIn.getPosition(); bytesIn.setBuffer(new byte[] {}); it.decodeConstant(in); assertThat(bytesIn.getPosition(), is(initialPosition)); }
@Test public void doesNotMoveInputStreamIfItDoesntReadTheConstantValue() throws IOException { // There should be more length bytes. byte[] badlyEncoded = "bar".getBytes(); bytesIn.setBuffer(badlyEncoded); int initialPosition = bytesIn.getPosition(); boolean raised = false; try { it.decodeConstant(in); } catch (ConstantType.DecodedWrongValueException e) { raised = true; } assertTrue(raised); assertThat(bytesIn.getPosition(), is(initialPosition)); }
@Test public void doesNotMoveInputStreamOnShortRead() throws IOException { // There should be more length bytes. byte[] shortEncoded = "fo".getBytes(); bytesIn.setBuffer(shortEncoded); int initialPosition = bytesIn.getPosition(); boolean raised = false; try { it.decodeConstant(in); } catch (EOFException ioe) { raised = true; } assertTrue(raised); assertThat(bytesIn.getPosition(), is(initialPosition)); }