DeviceID { public static DeviceID fromByteArray(byte[] deviceIDBytes) { if(deviceIDBytes == null) { throw new IllegalArgumentException("null device ID bytes"); } if(deviceIDBytes.length != ENOCEAN_ESP_ID_LENGTH) { throw new IllegalArgumentException( "Expected " + ENOCEAN_ESP_ID_LENGTH + "device ID bytes, got " + deviceIDBytes.length ); } long deviceIDValue = 0; deviceIDValue += (((long)deviceIDBytes[0] & 0xFFL) << 24); deviceIDValue += (((long)deviceIDBytes[1] & 0xFFL) << 16); deviceIDValue += (((long)deviceIDBytes[2] & 0xFFL) << 8); deviceIDValue += ((long)deviceIDBytes[3] & 0xFFL); return new DeviceID(deviceIDValue); } private  DeviceID(long deviceIDAs32BitValue); static DeviceID fromString(String deviceID); static DeviceID fromStringWithBaseID(String offset, DeviceID baseID); static DeviceID fromByteArray(byte[] deviceIDBytes); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); byte[] asByteArray(); DeviceID resolve(DeviceID baseID); static final DeviceID ENOCEAN_BROADCAST_ID; static final int ENOCEAN_ESP_ID_LENGTH; }
@Test (expected = IllegalArgumentException.class) public void testInvalidDeviceIDArrayLength() throws Exception { byte[] deviceIDbytes = new byte[] { (byte)0x01, (byte)0x02, (byte)0x03 }; DeviceID id = DeviceID.fromByteArray(deviceIDbytes); }