/*
 * 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.event.enrich;

import com.google.protobuf.Message;
import org.junit.Test;
import org.spine3.test.event.ProjectCreated;
import org.spine3.test.event.ProjectCreatedSeparateEnrichment;
import org.spine3.test.event.ProjectStarted;
import org.spine3.test.event.enrichment.ProjectCreatedEnrichmentAnotherPackage;
import org.spine3.test.event.enrichment.ProjectCreatedEnrichmentAnotherPackageFqn;
import org.spine3.test.event.enrichment.ProjectCreatedEnrichmentAnotherPackageFqnAndMsgOpt;
import org.spine3.type.TypeName;

import java.util.Map;

import static org.junit.Assert.*;
import static org.spine3.test.Tests.hasPrivateUtilityConstructor;

/**
 * @author Alexander Litus
 */
@SuppressWarnings("InstanceMethodNamingConvention")
public class EventEnrichmentsMapShould {

    @Test
    public void have_private_constructor() {
        assertTrue(hasPrivateUtilityConstructor(EventEnrichmentsMap.class));
    }

    @Test
    public void return_map_instance() {
        final Map<TypeName, TypeName> map = EventEnrichmentsMap.getInstance();

        assertFalse(map.isEmpty());
    }

    @Test
    public void contain_event_types_by_enrichment_type_names() {
        getEventTypeByEnrichmentTypeTest(ProjectCreated.class, ProjectCreated.Enrichment.class);
        getEventTypeByEnrichmentTypeTest(ProjectCreated.class, ProjectCreatedSeparateEnrichment.class);
        getEventTypeByEnrichmentTypeTest(ProjectCreated.class, ProjectCreatedEnrichmentAnotherPackage.class);
        getEventTypeByEnrichmentTypeTest(ProjectCreated.class, ProjectCreatedEnrichmentAnotherPackageFqn.class);
        getEventTypeByEnrichmentTypeTest(ProjectCreated.class, ProjectCreatedEnrichmentAnotherPackageFqnAndMsgOpt.class);
        getEventTypeByEnrichmentTypeTest(ProjectStarted.class, ProjectStarted.Enrichment.class);
    }

    private static void getEventTypeByEnrichmentTypeTest(Class<? extends Message> expectedEventClass,
                                                         Class<? extends Message> enrichmentClass) {
        final TypeName eventType = EventEnrichmentsMap.getInstance()
                                                      .get(TypeName.of(enrichmentClass));
        assertEquals(TypeName.of(expectedEventClass), eventType);
    }
}

@@ -2155,24 +2155,41 @@
 ain_
-event_types_by_e
+ProjectCreated_by_ProjectCreatedE
 nric
@@ -2202,14 +2202,8 @@
 type
-_names
 () %7B
@@ -2203,34 +2203,37 @@
 ype() %7B%0A        
-ge
+asser
 tEventTypeByEnri
@@ -2234,36 +2234,32 @@
 ByEnrichmentType
-Test
 (ProjectCreated.
@@ -2295,38 +2295,142 @@
 ent.class);%0A    
+%7D%0A%0A
     
-ge
+@Test%0A    public void contain_ProjectCreated_by_ProjectCreatedSeparateEnrichment_type() %7B%0A        asser
 tEventTypeByEnri
@@ -2431,36 +2431,32 @@
 ByEnrichmentType
-Test
 (ProjectCreated.
@@ -2499,38 +2499,148 @@
 ent.class);%0A    
+%7D%0A%0A
     
-ge
+@Test%0A    public void contain_ProjectCreated_by_ProjectCreatedEnrichmentAnotherPackage_type() %7B%0A        asser
 tEventTypeByEnri
@@ -2641,36 +2641,32 @@
 ByEnrichmentType
-Test
 (ProjectCreated.
@@ -2715,38 +2715,151 @@
 age.class);%0A    
+%7D%0A%0A
     
-ge
+@Test%0A    public void contain_ProjectCreated_by_ProjectCreatedEnrichmentAnotherPackageFqn_type() %7B%0A        asser
 tEventTypeByEnri
@@ -2860,36 +2860,32 @@
 ByEnrichmentType
-Test
 (ProjectCreated.
@@ -2937,38 +2937,160 @@
 Fqn.class);%0A    
+%7D%0A%0A
     
-ge
+@Test%0A    public void contain_ProjectCreated_by_ProjectCreatedEnrichmentAnotherPackageFqnAndMsgOpt_type() %7B%0A        asser
 tEventTypeByEnri
@@ -3091,36 +3091,32 @@
 ByEnrichmentType
-Test
 (ProjectCreated.
@@ -3189,14 +3189,110 @@
     
+%7D%0A%0A
     
-ge
+@Test%0A    public void contain_ProjectStarted_by_ProjectStartedEnrichment_type() %7B%0A        asser
 tEve
@@ -3313,20 +3313,16 @@
 mentType
-Test
 (Project
@@ -3401,18 +3401,21 @@
 ic void 
-ge
+asser
 tEventTy
@@ -3432,20 +3432,16 @@
 mentType
-Test
 (Class%3C?
@@ -3482,53 +3482,8 @@
 ss,%0A
-                                             
     

Split test method.