{
// we'll test making a couple EthernetAddresses and then check that
// asByteArray returns the same value in long form as used to create it
// first we'll test the null EthernetAddress
EthernetAddress ethernet_address = new EthernetAddress(0L);
assertEquals("Expected length of returned array wrong",
ETHERNET_ADDRESS_ARRAY_LENGTH,
ethernet_address.asByteArray().length);
assertEthernetAddressArraysAreEqual(
NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
ethernet_address.asByteArray(), 0);
// now test a non-null EthernetAddress
ethernet_address = new EthernetAddress(VALID_ETHERNET_ADDRESS_LONG);
assertEquals("Expected length of returned array wrong",
ETHERNET_ADDRESS_ARRAY_LENGTH,
ethernet_address.asByteArray().length);
assertEthernetAddressArraysAreEqual(
VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
ethernet_address.asByteArray(), 0);
// let's make sure that changing the returned array doesn't mess with
// the wrapped EthernetAddress's internals
byte[] ethernet_address_byte_array = ethernet_address.asByteArray();
// we'll just stir it up a bit and then check that the original
// EthernetAddress was not changed in the process.
// The easiest stir is to sort it ;)
Arrays.sort(ethernet_address_byte_array);
assertEthernetAddressArraysAreNotEqual(
VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
ethernet_address_byte_array, 0);
assertEthernetAddressArraysAreNotEqual(
ethernet_address.asByteArray(), 0,
ethernet_address_byte_array, 0);
assertEthernetAddressArraysAreEqual(
VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
ethernet_address.asByteArray(), 0);
}