/*
 * Copyright 2019, TeamDev. 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 io.spine.server.type;

import com.google.common.testing.NullPointerTester;
import io.spine.test.core.ProjectCreated;
import io.spine.test.core.ProjectId;
import io.spine.type.TypeUrl;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static io.spine.testing.DisplayNames.NOT_ACCEPT_NULLS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@DisplayName("EventClass should")
class EventClassTest {

    @Test
    @DisplayName(NOT_ACCEPT_NULLS)
    void passNullToleranceCheck() {
        new NullPointerTester()
                .testAllPublicStaticMethods(EventClass.class);
    }

    @Test
    @DisplayName("be constructed from TypeUrl instance")
    void constructFromTypeUrl() {
        TypeUrl typeUrl = TypeUrl.from(ProjectCreated.getDescriptor());
        EventClass eventClass = EventClass.from(typeUrl);
        assertEquals(ProjectCreated.class, eventClass.value());
    }

    @SuppressWarnings({"CheckReturnValue", "ResultOfMethodCallIgnored"})
    // Method called to throw exception.
    @Test
    @DisplayName("throw IAE when constructing from non-event type URL")
    void throwOnNonEventType() {
        TypeUrl typeUrl = TypeUrl.from(ProjectId.getDescriptor());
        assertThrows(IllegalArgumentException.class, () -> EventClass.from(typeUrl));
    }
}

@@ -1089,16 +1089,112 @@
 Tester;%0A
+import com.google.protobuf.Any;%0Aimport io.spine.core.Event;%0Aimport io.spine.protobuf.AnyPacker;%0A
 import i
@@ -1369,14 +1369,155 @@
 api.
-Test;%0A
+Nested;%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport static com.google.common.truth.Truth.assertThat;%0Aimport static io.spine.base.Identifier.newUuid;
 %0Aimp
@@ -1579,69 +1579,8 @@
 LS;%0A
-import static org.junit.jupiter.api.Assertions.assertEquals;%0A
 impo
@@ -1651,16 +1651,17 @@
 ayName(%22
+%60
 EventCla
@@ -1662,16 +1662,17 @@
 entClass
+%60
  should%22
@@ -1881,28 +1881,30 @@
     %7D%0A%0A    @
-T
+N
 est
+ed
 %0A    @Displa
@@ -1928,21 +1928,88 @@
 cted
- 
+%22)%0A    class BeConstructed %7B%0A%0A        @Test%0A        @DisplayName(%22
 from 
+%60
 TypeUrl
+%60
  ins
@@ -2024,23 +2024,18 @@
     
+  
+  
 void 
-constructF
+f
 romT
@@ -2041,24 +2041,28 @@
 TypeUrl() %7B%0A
+    
         Type
@@ -2129,16 +2129,20 @@
         
+  
+  
 EventCla
@@ -2195,63 +2195,806 @@
     
+    
 assert
-Equals(ProjectCreated.class, eventClass.value());
+That(eventClass.value()).isEqualTo(ProjectCreated.class);%0A        %7D%0A%0A        @Test%0A        @DisplayName(%22from %60Event%60 instance%22)%0A        void fromEvent() %7B%0A            ProjectId id = ProjectId%0A                    .newBuilder()%0A                    .setId(newUuid())%0A                    .build();%0A            ProjectCreated projectCreated = ProjectCreated%0A                    .newBuilder()%0A                    .setProjectId(id)%0A                    .build();%0A            Any any = AnyPacker.pack(projectCreated);%0A            Event event = Event%0A                    .newBuilder()%0A                    .setMessage(any)%0A                    .build();%0A            EventClass eventClass = EventClass.from(event);%0A            assertThat(eventClass.value()).isEqualTo(ProjectCreated.class);%0A        %7D
 %0A   

Add a test for `EventClass` creation from `Event`