Пример #1
0
  @Test
  public void decodesTheConstantValueAsIs() throws IOException {
    int initialPosition = bytesIn.getPosition();

    bytesIn.setBuffer(encoded);
    it.decodeConstant(in);

    assertThat(bytesIn.getPosition(), is(initialPosition + encoded.length));
  }
Пример #2
0
  @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));
  }
Пример #3
0
  @Before
  public void setUp() {
    it = new ConstantType("foo");

    decoded = it.getStringValue().getBytes();
    encoded = it.getStringValue().getBytes();

    bytesOut = new ByteArrayOutputStream();
    out = new DataOutputStream(bytesOut);
    bytesIn = new ReusableByteArrayInputStream();
    in = new DataInputStream(bytesIn);
  }
Пример #4
0
  @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));
  }
Пример #5
0
  @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));
  }
Пример #6
0
 @Test
 public void encodesTheConstantValueAsIs() throws IOException {
   it.encodeConstant(out);
   assertThat(bytesOut.toByteArray(), is(encoded));
 }
Пример #7
0
 @Test
 public void isConstant() {
   assertThat(it.isConstant(), is(true));
 }
Пример #8
0
 @Test
 public void isWellFormed() {
   assertThat(it.isWellFormed(), is(true));
 }
Пример #9
0
 @Test
 public void hasASolitaryValue() {
   assertThat(it.getStringValue(), is("foo"));
   assertThat(it.getValue(), is("foo".getBytes()));
 }
Пример #10
0
 @Test
 public void isByteAligned() {
   assertThat(it.isByteAligned(), is(true));
   assertThat(it.isInternallyByteAligned(), is(true));
 }
Пример #11
0
 @Test
 public void isAsWideAsTheUTF8EncodingOfTheStringPassedAtConstruction() {
   assertThat(new ConstantType("f\u00f6\u00f6").getBitWidth(), is(40));
   assertThat(it.isWholeByteSized(), is(true));
 }
Пример #12
0
 @Test
 public void isFixedWidth() {
   assertThat(it.isFixedWidth(), is(true));
   assertThat(it.isStreamDecodeable(), is(true));
   assertThat(it.isDecodeable(), is(true));
 }
Пример #13
0
 @Test
 public void isPackable() {
   assertThat(it.isPackable(), is(true));
 }
Пример #14
0
 @Test
 public void isNotNameable() {
   assertThat(it.isNameable(), is(false));
 }
Пример #15
0
 @Test
 public void encodesTheEmptyConstant() throws IOException {
   it = new ConstantType("");
   it.encodeConstant(out);
   assertThat(bytesOut.toByteArray(), is(new byte[] {}));
 }