Examples of EthernetAddress


Examples of com.fasterxml.uuid.EthernetAddress

    {
        // we'll test making a couple EthernetAddresses and then check that the
        // toByteArray returns the same value in byte 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.toByteArray().length);
        assertEthernetAddressArraysAreEqual(
            NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            ethernet_address.toByteArray(), 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.toByteArray().length);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            ethernet_address.toByteArray(), 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.toByteArray();
        // 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.toByteArray(), 0,
            ethernet_address_byte_array, 0);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            ethernet_address.toByteArray(), 0);
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

       
        // lets test some error cases
        // first, passing null
        try
        {
            EthernetAddress ethernet_address = new EthernetAddress(0L);
            ethernet_address.toByteArray((byte[])null);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        }
        catch (NullPointerException ex)
        {
            // this is the success case so do nothing
        }
        catch (Exception ex)
        {
            fail("Caught unexpected exception: " + ex);
        }
       
        // now an array that is too small
        try {
            EthernetAddress ethernet_address = new EthernetAddress(0L);
            byte[] ethernet_address_byte_array =
                new byte[ETHERNET_ADDRESS_ARRAY_LENGTH - 1];
            ethernet_address.toByteArray(ethernet_address_byte_array);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        } catch (IllegalArgumentException ex) {
            // this is the success case so do nothing
        } catch (Exception ex) {
            fail("Caught unexpected exception: " + ex);
        }

        // we'll test making a couple EthernetAddresses and then check that
        // toByteArray returns the same value in byte form as used to create it
       
        // here we'll test the null EthernetAddress
        EthernetAddress ethernet_address = new EthernetAddress(0L);
        byte[] test_array = new byte[ETHERNET_ADDRESS_ARRAY_LENGTH];
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array);
        assertEthernetAddressArraysAreEqual(
            NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
       
        // now test a non-null EthernetAddress
        ethernet_address = new EthernetAddress(MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING);
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
       
        // now test a null EthernetAddress case with extra data in the array
        ethernet_address = new EthernetAddress(0L);
        test_array = new byte[ETHERNET_ADDRESS_ARRAY_LENGTH + EXTRA_DATA_LENGTH];
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array);
        assertEthernetAddressArraysAreEqual(NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
        for (int i = 0; i < EXTRA_DATA_LENGTH; i++)
        {
            assertEquals("Expected array fill value changed",
                        (byte)'x',
                        test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH]);
        }
       
        // now test a good EthernetAddress case with extra data in the array
        ethernet_address =
            new EthernetAddress(MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING);
        test_array =
            new byte[ETHERNET_ADDRESS_ARRAY_LENGTH + EXTRA_DATA_LENGTH];
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
        for (int i = 0; i < EXTRA_DATA_LENGTH; i++)
        {
            assertEquals("Expected array fill value changed",
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

       
        // lets test some error cases
        // first, passing null and 0
        try
        {
            EthernetAddress ethernet_address = new EthernetAddress(0L);
            ethernet_address.toByteArray((byte[])null, 0);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        }
        catch (NullPointerException ex)
        {
            // this is the success case so do nothing
        }
        catch (Exception ex)
        {
            fail("Caught unexpected exception: " + ex);
        }
       
        // now an array that is too small
        try
        {
            EthernetAddress ethernet_address = new EthernetAddress(0L);
            byte[] ethernet_address_byte_array =
                new byte[ETHERNET_ADDRESS_ARRAY_LENGTH - 1];
            ethernet_address.toByteArray(ethernet_address_byte_array, 0);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        } catch (IllegalArgumentException ex) {
            // this is the success case so do nothing
        } catch (Exception ex) {
            fail("Caught unexpected exception: " + ex);
        }

        // now an index that is negative
        try {
            EthernetAddress ethernet_address = new EthernetAddress(0L);
            byte[] ethernet_address_byte_array =
                new byte[ETHERNET_ADDRESS_ARRAY_LENGTH];
            ethernet_address.toByteArray(ethernet_address_byte_array, -1);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        } catch (IllegalArgumentException ex) {
            // this is the success case so do nothing
        } catch (Exception ex) {
            fail("Caught unexpected exception: " + ex);
        }
       
        // now an index that is too big
        try
        {
            EthernetAddress ethernet_address = new EthernetAddress(0L);
            byte[] ethernet_address_byte_array =
                new byte[ETHERNET_ADDRESS_ARRAY_LENGTH];
            ethernet_address.toByteArray(
                ethernet_address_byte_array, ETHERNET_ADDRESS_ARRAY_LENGTH);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        } catch (IllegalArgumentException ex) {
            // this is the success case so do nothing
        } catch (Exception ex) {
            fail("Caught unexpected exception: " + ex);
        }
       
        // now an index that is in the array,
        // but without enough bytes to read ETHERNET_ADDRESS_ARRAY_LENGTH
        try {
            EthernetAddress ethernet_address = new EthernetAddress(0L);
            byte[] ethernet_address_byte_array =
                new byte[ETHERNET_ADDRESS_ARRAY_LENGTH];
            ethernet_address.toByteArray(ethernet_address_byte_array, 1);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        } catch (IllegalArgumentException ex) {
            // this is the success case so do nothing
        } catch (Exception ex) {
            fail("Caught unexpected exception: " + ex);
        }
       
        // we'll test making a couple EthernetAddresss and then check
        // that toByteArray
        // returns the same value in byte form as used to create it
       
        // here we'll test the null EthernetAddress at offset 0
        EthernetAddress ethernet_address = new EthernetAddress(0L);
        byte[] test_array = new byte[ETHERNET_ADDRESS_ARRAY_LENGTH];
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array, 0);
        assertEthernetAddressArraysAreEqual(
            NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
       
        // now test a non-null EthernetAddress
        ethernet_address =
            new EthernetAddress(MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING);
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
       
        // now test a null EthernetAddress case with extra data in the array
        ethernet_address = new EthernetAddress(0L);
        test_array =
            new byte[ETHERNET_ADDRESS_ARRAY_LENGTH + EXTRA_DATA_LENGTH];
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array, 0);
        assertEthernetAddressArraysAreEqual(
            NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
        for (int i = 0; i < EXTRA_DATA_LENGTH; i++) {
            assertEquals("Expected array fill value changed",
                        (byte)'x',
                        test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH]);
        }
       
        // now test a null EthernetAddress case with extra data in the array
        ethernet_address = new EthernetAddress(0L);
        test_array = new byte[ETHERNET_ADDRESS_ARRAY_LENGTH + EXTRA_DATA_LENGTH];
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array, EXTRA_DATA_LENGTH/2);
        assertEthernetAddressArraysAreEqual(
            NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            test_array, EXTRA_DATA_LENGTH/2);
        for (int i = 0; i < EXTRA_DATA_LENGTH/2; i++)
        {
            assertEquals("Expected array fill value changed",
                (byte)'x',
                test_array[i]);
            assertEquals("Expected array fill value changed",
                (byte)'x',
                test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH +
                    EXTRA_DATA_LENGTH/2]);
        }
       
        // now test a good EthernetAddress case with extra data in the array
        ethernet_address =
            new EthernetAddress(MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING);
        test_array =
            new byte[ETHERNET_ADDRESS_ARRAY_LENGTH + EXTRA_DATA_LENGTH];
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array, 0);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0, test_array, 0);
        for (int i = 0; i < EXTRA_DATA_LENGTH; i++)
        {
            assertEquals("Expected array fill value changed",
                        (byte)'x',
                        test_array[i + ETHERNET_ADDRESS_ARRAY_LENGTH]);
        }

        // now test a good EthernetAddress case with extra data in the array
        ethernet_address =
            new EthernetAddress(MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING);
        test_array =
            new byte[ETHERNET_ADDRESS_ARRAY_LENGTH + EXTRA_DATA_LENGTH];
        Arrays.fill(test_array, (byte)'x');
        ethernet_address.toByteArray(test_array, EXTRA_DATA_LENGTH/2);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            test_array, EXTRA_DATA_LENGTH/2);
        for (int i = 0; i < EXTRA_DATA_LENGTH/2; i++)
        {
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

    {
        // test making a couple EthernetAddresss and then check that the toLong
        // gives back the same value in long form that was used to create it
       
        // test the null EthernetAddress
        EthernetAddress ethernet_address = new EthernetAddress(0L);
        assertEquals("null EthernetAddress long and toLong did not match",
                    NULL_ETHERNET_ADDRESS_LONG,
                    ethernet_address.toLong());
       
        // test a non-null EthernetAddress
        ethernet_address =
            new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertEquals("EthernetAddress long and toLong results did not match",
                    VALID_ETHERNET_ADDRESS_LONG,
                    ethernet_address.toLong());
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

    {
        // test making a few EthernetAddresss and check that the toString
        // gives back the same value in string form that was used to create it
       
        // test the null EthernetAddress
        EthernetAddress ethernet_address = new EthernetAddress(0L);
        assertEquals("null EthernetAddress string and toString did not match",
                    NULL_ETHERNET_ADDRESS_STRING.toLowerCase(),
                    ethernet_address.toString().toLowerCase());
       
        // test a non-null EthernetAddress
        ethernet_address =
            new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertEquals(
            "EthernetAddress string and toString results did not match",
            MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.toLowerCase(),
            ethernet_address.toString().toLowerCase());
       
        // EthernetAddress implementation returns strings all lowercase.
        // Although relying on this behavior in code is not recommended,
        // here is a unit test which will break if this assumption
        // becomes bad. This will act as an early warning to anyone
        // who relies on this particular behavior.
        ethernet_address =
            new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertFalse("mixed case EthernetAddress string and toString " +
                "matched (expected toString to be all lower case)",
            MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.equals(
                ethernet_address.toString()));
        assertEquals("mixed case string toLowerCase and " +
                "toString results did not match (expected toString to " +
                "be all lower case)",
            MIXED_CASE_VALID_ETHERNET_ADDRESS_STRING.toLowerCase(),
                ethernet_address.toString());
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

            fail("Caught unexpected exception: " + ex);
        }

        // test that creating a EthernetAddress from an zero'd array
        // gives us a null EthernetAddress (definition of null EthernetAddress)
        EthernetAddress ethernet_address =
            EthernetAddress.valueOf(new byte[ETHERNET_ADDRESS_ARRAY_LENGTH]);
        assertEquals(
            "EthernetAddress.valueOf did not create expected EthernetAddress",
            NULL_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
       
        // let's test creating an array from a good byte array
        ethernet_address =
            EthernetAddress.valueOf(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertEquals(
            "EthernetAddress.valueOf did not create expected EthernetAddress",
            VALID_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

            fail("Caught unexpected exception: " + ex);
        }

        // let's test that creating a EthernetAddress from an zero'd array
        // gives a null EthernetAddress (definition of a null EthernetAddress)
        EthernetAddress ethernet_address =
            EthernetAddress.valueOf(new int[ETHERNET_ADDRESS_ARRAY_LENGTH]);
        assertEquals(
            "EthernetAddress.valueOf did not create expected EthernetAddress",
            NULL_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
       
        // let's test creating an array from a good int array
        ethernet_address =
            EthernetAddress.valueOf(VALID_ETHERNET_ADDRESS_INT_ARRAY);
        assertEquals(
            "EthernetAddress.valueOf did not create expected EthernetAddress",
            VALID_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

     */
    public void testValueOfLong()
    {
        // let's test that creating a EthernetAddress from an zero long
        // gives a null EthernetAddress (definition of a null EthernetAddress)
        EthernetAddress ethernet_address =
            EthernetAddress.valueOf(0x0000000000000000L);
        assertEquals(
            "EthernetAddress.valueOf did not create expected EthernetAddress",
            NULL_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
       
        // let's test creating an array from a good long
        ethernet_address =
            EthernetAddress.valueOf(VALID_ETHERNET_ADDRESS_LONG);
        assertEquals(
            "EthernetAddress.valueOf did not create expected EthernetAddress",
            VALID_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

     *
     * @since 3.0
     */
    public void testFromInterface() throws Exception
    {
        EthernetAddress addr = EthernetAddress.fromInterface();
        assertNotNull(addr);
        assertNotNull(addr.toString());
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

    public void testBogus() throws Exception
    {
        // First, two using pseudo-random; verify they are different
        Random r = new Random(123);
        EthernetAddress a1 = EthernetAddress.constructMulticastAddress(r);
        assertNotNull(a1);
        assertEquals(a1, a1);
        assertTrue(a1.isMulticastAddress());
        EthernetAddress a2 = EthernetAddress.constructMulticastAddress(r);
        assertNotNull(a2);
        assertTrue(a2.isMulticastAddress());
        assertEquals(a2, a2);
        assertFalse(a1.equals(a2));

        // and then default, which uses SecureRandom
        EthernetAddress a3 = EthernetAddress.constructMulticastAddress();
        assertNotNull(a3);
        assertNotNull(a3.toString());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.