AmsError extends UnsignedIntLEByteValue { public static AmsError of(byte... values) { return new AmsError(values); } private  AmsError(byte... values); private  AmsError(long value); private  AmsError(ByteBuf byteBuf); static AmsError of(byte... values); static AmsError of(long errorCode); static AmsError of(AdsReturnCode errorCode); static AmsError of(String errorCode); static AmsError of(ByteBuf byteBuf); AdsReturnCode toAdsReturnCode(); @Override String toString(); static final int NUM_BYTES; static final AmsError NONE; }
@Test public void errorBytes() { AmsError error = AmsError.of((byte)0x01, (byte)0x20, (byte)0x00, (byte)0x00); assertThat(error.getAsLong(), is(0x2001L)); }
@Test public void errorLong() { AmsError error = AmsError.of(0xFF02L); assertThat(error.getAsLong(), is(0xFF02L)); }
@Test public void errorLongBig() { AmsError error = AmsError.of(0xFFFFFFFFL); assertThat(error.getAsLong(), is(0xFFFFFFFFL)); }
@Test public void errorString() { AmsError error = AmsError.of("255"); assertThat(error.getAsLong(), is(0xFFL)); }
@Test public void errorByteBuf() { ByteBuf buffer = Unpooled.buffer(); buffer.writeByte((byte)0x04); buffer.writeByte((byte)0x01); buffer.writeByte((byte)0x00); buffer.writeByte((byte)0x00); AmsError error = AmsError.of(buffer); assertThat(error.getAsLong(), is(260L)); }
@Test(expected = NumberFormatException.class) public void noHex() { AmsError error = AmsError.of("0xFF000000"); }
@Test(expected = IllegalArgumentException.class) public void errorLongTooBig() { AmsError error = AmsError.of(0x100000000L); }
@Test(expected = IllegalArgumentException.class) public void errorNegative() { AmsError error = AmsError.of(-1); }
@Test public void equals() { AmsError a = AmsError.of((byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4); AmsError b = AmsError.of((byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4); AmsError c = AmsError.of((byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0xFF); byte array[] = {(byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4}; assertThat(a.equals(a), is(true)); assertThat(a.equals(b), is(true)); assertThat(a.equals(c), is(false)); assertThat(a.equals(1), is(false)); assertThat(a.equals((byte) 1), is(false)); assertThat(a.equals(array), is(false)); }