DecodeBoolean implements IpfixDataRecordDecodeMethod { @Override public String decodeDataRecord(byte[] data, int length) throws UtilityException, DataTypeLengthMismatchException { if (length != LENGTH) { throw new DataTypeLengthMismatchException("Incorrect length for Boolean type: " + length); } data = IpfixUtilities.copyByteArray(data, 0, LENGTH); String value = (data[0] == 1) ? TRUE_VALUE : FALSE_VALUE; return String.valueOf(value); }  @Override String decodeDataRecord(byte[] data, int length);  }
@Test public void testDecodeBoolean() throws UtilityException, DataTypeLengthMismatchException, UnknownHostException, MissingAbstractDataTypeException { byte[] data = IpfixUtilities.hexStringToByteArray("01"); int length = 1; IpfixDataRecordDecodeMethod method = new DecodeBoolean(); String value = method.decodeDataRecord(data, length); assertEquals("True", value); }
@Test(expected = DataTypeLengthMismatchException.class) public void testDecodeBooleanLengthMismatch() throws UtilityException, DataTypeLengthMismatchException, UnknownHostException, MissingAbstractDataTypeException { byte[] data = IpfixUtilities.hexStringToByteArray("01"); int length = 2; IpfixDataRecordDecodeMethod method = new DecodeBoolean(); String value = method.decodeDataRecord(data, length); assertEquals("True", value); }