/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.base;

import com.google.protobuf.Timestamp;
import org.junit.Test;
import org.spine3.base.Identifier.Type;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.spine3.protobuf.Values.newIntValue;
import static org.spine3.protobuf.Values.newStringValue;
import static org.spine3.protobuf.Values.newUInt64Value;
import static org.spine3.protobuf.Values.newUIntValue;

@SuppressWarnings({"InstanceMethodNamingConvention", "ClassWithTooManyMethods", "MagicNumber"})
public class IdentifierShould {

    @Test
    public void getDefaultValue_by_class_id() {
        assertEquals(0L, Identifier.getDefaultValue(Long.class).longValue());
        assertEquals(0, Identifier.getDefaultValue(Integer.class).intValue());
        assertEquals("", Identifier.getDefaultValue(String.class));
        assertEquals(Timestamp.getDefaultInstance(), Identifier.getDefaultValue(Timestamp.class));
    }

    @Test
    public void create_values_by_type() {
        assertTrue(Identifier.from("").isString());
        assertTrue(Identifier.from(0).isInteger());
        assertTrue(Identifier.from(0L).isLong());
        assertTrue(Identifier.from(0L).isLong());
        assertTrue(Identifier.from(newIntValue(300)).isMessage());
    }

    @Test(expected = IllegalArgumentException.class)
    public void do_not_accept_values_of_unsupported_types() {
        Identifier.from(0.0).toString();
    }

    @Test
    public void recognize_type_by_supported_message_type() {
        assertTrue(Type.INTEGER.matchMessage(newUIntValue(10)));
        assertTrue(Type.LONG.matchMessage(newUInt64Value(1020L)));
        assertTrue(Type.STRING.matchMessage(newStringValue("")));
        assertTrue(Type.MESSAGE.matchMessage(Timestamp.getDefaultInstance()));
    }
}

@@ -1032,24 +1032,56 @@
 ine3.base;%0A%0A
+import com.google.protobuf.Any;%0A
 import com.g
@@ -1106,16 +1106,16 @@
 estamp;%0A
-
 import o
@@ -1254,24 +1254,81 @@
 assertTrue;%0A
+import static org.spine3.protobuf.Values.newDoubleValue;%0A
 import stati
@@ -2267,58 +2267,8 @@
 ));%0A
-        assertTrue(Identifier.from(0L).isLong());%0A
     
@@ -2765,24 +2765,24 @@
 alue(%22%22)));%0A
-
         asse
@@ -2853,11 +2853,473 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void create_values_depending_from_message_type() %7B%0A        assertEquals(10, Type.INTEGER.fromMessage(newUIntValue(10)));%0A        assertEquals(1024L, Type.LONG.fromMessage(newUInt64Value(1024L)));%0A        assertEquals(%22%22, Type.STRING.fromMessage(newStringValue(%22%22)));%0A    %7D%0A%0A    @Test(expected = IllegalArgumentException.class)%0A    public void not_unpack_usupported_types () %7B%0A        Identifier.Type.unpack(Any.getDefaultInstance());%0A    %7D
 %0A%7D%0A

Add tests for `unpack` and `fromMessage` methods for `Identifier`.