Package org.internna.iwebmvc.model.hibernate

Source Code of org.internna.iwebmvc.model.hibernate.UUIDTest

/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache license, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.internna.iwebmvc.model.hibernate;

import org.internna.iwebmvc.model.UUID;
import org.junit.Test;
import org.junit.BeforeClass;
import static org.junit.Assert.*;
import org.internna.iwebmvc.utils.StringUtils;

public class UUIDTest {

    private static byte[] uuid2_bytes;
    private static UUID uuid, uuid2;

    @BeforeClass
    public static void setUp() {
        uuid = new UUID("3b0ae7d419d26e36e040007f0101785c");
        uuid2_bytes = StringUtils.encodeHex("987654321098765432109876543210aa");
        uuid2 = new UUID(uuid2_bytes);
    }

    @Test
    public void testEquals() {
        assertFalse("Null is not equal to any UUID", uuid.equals(null));
        assertEquals("Two UUIDs are equal if they are the same", uuid, uuid);
        assertEquals("Two UUIDs constructed in a diffenrent way may be equal", uuid2, new UUID("987654321098765432109876543210aa"));
        assertFalse("Different UUIDs cannot be equal", uuid.equals(uuid2));
    }

    @Test
    public void testHashcode() {
        assertEquals("Two UUIDs hashcodes are the same", uuid.hashCode(), uuid.hashCode());
        assertFalse("Two different UUIDs hashcodes are different", uuid.hashCode() == uuid2.hashCode());
    }

    @Test
    public void testGetBytes() {
        assertNotSame("A copy is returned", uuid2_bytes, uuid2.getBytes());
        assertTrue("Lower values are the same", uuid2_bytes[0] == uuid2.getBytes()[0]);
        assertTrue("Higher values are the same", uuid2_bytes[15] == uuid2.getBytes()[15]);
    }

    @Test
    public void testToString() {
        assertEquals("Hex encoded string", "3b0ae7d419d26e36e040007f0101785c", uuid.toString());
    }

}
TOP

Related Classes of org.internna.iwebmvc.model.hibernate.UUIDTest

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.