/*
 * Copyright 2016, 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.server.type;

import com.google.protobuf.Message;
import com.google.protobuf.StringValue;
import com.google.protobuf.UInt32Value;
import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@SuppressWarnings({"InstanceMethodNamingConvention", "EmptyClass"})
public class MessageClassShould {

    @Test
    public void return_enclosed_value() {
        final Class<? extends Message> expected = StringValue.class;
        Assert.assertEquals(expected, new  MessageClass(expected) {}.value());
    }

    @Test
    public void be_not_equal_to_null() {
        //noinspection ObjectEqualsNull
        assertFalse(new MessageClass(UInt32Value.class){}.equals(null));
    }

    @Test
    public void be_not_equal_to_object_of_another_class() {
        // Notice that we're creating new inner classes here with the same value passed.
        //noinspection EqualsBetweenInconvertibleTypes
        assertFalse(new MessageClass(StringValue.class){}.equals(new MessageClass(StringValue.class){}));
    }

    @Test
    public void be_equal_to_self() {
        final MessageClass test = new MessageClass(UInt32Value.class){};
        //noinspection EqualsWithItself
        assertTrue(test.equals(test));
    }
}

@@ -1130,38 +1130,23 @@
 ort 
-com.google.protobuf.UInt32Valu
+org.junit.Befor
 e;%0Ai
@@ -1161,21 +1161,19 @@
 g.junit.
-Asser
+Tes
 t;%0Aimpor
@@ -1182,64 +1182,58 @@
 org.
-junit.Test;%0A%0Aimport static org.junit.Assert.assertFalse;
+spine3.type.ClassName;%0A%0Aimport java.util.Objects;%0A
 %0Aimp
@@ -1260,26 +1260,17 @@
 .Assert.
-assertTrue
+*
 ;%0A%0A@Supp
@@ -1375,198 +1375,731 @@
     
-@Test%0A    public void return_enclosed_value() %7B%0A        final Class%3C? extends Message%3E expected = 
+private static final Class%3CStringValue%3E MSG_CLASS = StringValue.class;%0A%0A    private TestMessageClass testMsgClass;%0A%0A    @Before%0A    public void setUpTest() %7B%0A        testMsgClass = new TestMessageClass(MSG_CLASS);%0A    %7D%0A%0A    @Test%0A    public void return_enclosed_value() %7B%0A        assertEquals(MSG_CLASS, testMsgClass.value());%0A    %7D%0A%0A    @Test%0A    public void return_java_class_name() %7B%0A        assertEquals(ClassName.of(MSG_CLASS), testMsgClass.getClassName());%0A    %7D%0A    %0A    @Test%0A    public void convert_value_to_string() %7B%0A        assertEquals(
 String
-V
+.v
 alue
-.class
+Of(MSG_CLASS), testMsgClass.toString())
 ;%0A    
+%7D%0A%0A
     
-Assert.assertEquals(expected, new  MessageClass(expected) %7B%7D.valu
+@Test%0A    public void return_hash_code() %7B%0A        assertEquals(Objects.hash(MSG_CLASS), testMsgClass.hashCod
 e())
@@ -2216,65 +2216,37 @@
 sert
-False(new MessageClass(UInt32Value.class)%7B%7D.equals(
+NotEquals(testMsgClass, 
 null)
-)
 ;%0A  
@@ -2362,30 +2362,20 @@
 ing 
+a 
 new 
-inner classes here
+object
  wit
@@ -2472,96 +2472,206 @@
 sert
-False(new MessageClass(StringValue.class)%7B%7D.equals(new MessageClass(StringValue.class)%7B%7D
+NotEquals(testMsgClass, new MessageClass(MSG_CLASS) %7B%7D);%0A    %7D%0A%0A    @Test%0A    public void be_equal_to_object_with_the_same_value() %7B%0A        assertEquals(testMsgClass, new TestMessageClass(MSG_CLASS
 ));%0A
@@ -2736,151 +2736,227 @@
     
-final Message
+assertEquals(testMsg
 Class
+,
  test
- = new MessageClass(UInt32Value.class)%7B%7D;%0A        //noinspection EqualsWithItself%0A        assertTrue(test.equals(test));
+MsgClass);%0A    %7D%0A%0A    private static class TestMessageClass extends MessageClass %7B%0A%0A        protected TestMessageClass(Class%3C? extends Message%3E value) %7B%0A            super(value);%0A        %7D
 %0A   

Add MessageClass tests.