/*
 * Copyright 2018, 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.testing.server.procman;

import com.google.common.testing.NullPointerTester;
import io.spine.core.Command;
import io.spine.core.CommandEnvelope;
import io.spine.core.EventEnvelope;
import io.spine.core.RejectionEnvelope;
import io.spine.server.procman.ProcessManager;
import io.spine.testing.client.TestActorRequestFactory;
import io.spine.testing.server.TestEventFactory;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static io.spine.core.Rejections.createRejection;
import static io.spine.testing.DisplayNames.HAVE_PARAMETERLESS_CTOR;
import static io.spine.testing.DisplayNames.NOT_ACCEPT_NULLS;
import static io.spine.testing.TestValues.newUuidValue;
import static io.spine.testing.Tests.assertHasPrivateParameterlessCtor;
import static org.mockito.Mockito.mock;

/**
 * @author Alexander Yevsyukov
 */
@DisplayName("ProcessManagerDispatcher utility should")
class PmDispatcherTest {

    @Test
    @DisplayName(HAVE_PARAMETERLESS_CTOR)
    void haveUtilityConstructor() {
        assertHasPrivateParameterlessCtor(PmDispatcher.class);
    }

    @Test
    @DisplayName(NOT_ACCEPT_NULLS)
    void passNullToleranceCheck() {
        TestActorRequestFactory requestFactory =
                TestActorRequestFactory.newInstance(getClass());
        TestEventFactory eventFactory = TestEventFactory.newInstance(getClass());

        Command command = requestFactory.generateCommand();
        new NullPointerTester()
                .setDefault(CommandEnvelope.class,
                            CommandEnvelope.of(command))
                .setDefault(EventEnvelope.class,
                            EventEnvelope.of(eventFactory.createEvent(newUuidValue())))
                .setDefault(RejectionEnvelope.class,
                            RejectionEnvelope.of(createRejection(newUuidValue(), command)))
                .setDefault(ProcessManager.class, mock(ProcessManager.class))
                .testAllPublicStaticMethods(PmDispatcher.class);
    }
}

@@ -1194,24 +1194,84 @@
 re.Event
-Envelope
+;%0Aimport io.spine.core.EventEnvelope;%0Aimport io.spine.core.Rejection
 ;%0Aimport
@@ -1347,24 +1347,66 @@
 essManager;%0A
+import io.spine.testing.UtilityClassTest;%0A
 import io.sp
@@ -1543,43 +1543,8 @@
 ame;
-%0Aimport org.junit.jupiter.api.Test;
 %0A%0Aim
@@ -1632,644 +1632,251 @@
 ing.
-DisplayNames.HAVE_PARAMETERLESS_CTOR;%0Aimport static io.spine.testing.DisplayNames.NOT_ACCEPT_NULLS;%0Aimport static io.spine.testing.TestValues.newUuidValue;%0Aimport static io.spine.testing.Tests.assertHasPrivateParameterlessCtor;%0Aimport static org.mockito.Mockito.mock;%0A%0A/**%0A * @author Alexander Yevsyukov%0A */%0A@DisplayName(%22ProcessManagerDispatcher utility should%22)%0Aclass PmDispatcherTest %7B%0A%0A    @Test%0A    @DisplayName(HAVE_PARAMETERLESS_CTOR)%0A    void haveUtilityConstructor() %7B%0A        assertHasPrivateParameterlessCtor(PmDispatcher.class);%0A    %7D%0A%0A    @Test%0A    @DisplayName(NOT_ACCEPT_NULLS)%0A    void passNullToleranceCheck() %7B%0A       
+TestValues.newUuidValue;%0Aimport static org.mockito.Mockito.mock;%0A%0A/**%0A * @author Alexander Yevsyukov%0A */%0A@DisplayName(%22ProcessManagerDispatcher utility should%22)%0Aclass PmDispatcherTest extends UtilityClassTest%3CPmDispatcher%3E %7B%0A%0A    private final
  Tes
@@ -1921,28 +1921,24 @@
             
-   
- 
 TestActorReq
@@ -1974,27 +1974,37 @@
 ass());%0A    
-   
+private final
  TestEventFa
@@ -2075,112 +2075,354 @@
     
-    Command command = requestFactory.generateCommand();%0A        new NullPointerTester()%0A                
+PmDispatcherTest() %7B%0A        super(PmDispatcher.class);%0A    %7D%0A%0A    @Override%0A    protected void setDefaults(NullPointerTester tester) %7B%0A        Command command = requestFactory.generateCommand();%0A        Event event = eventFactory.createEvent(newUuidValue());%0A        Rejection rejection = createRejection(newUuidValue(), command);%0A        tester
 .set
@@ -2444,34 +2444,32 @@
 Envelope.class,%0A
-  
                 
@@ -2513,34 +2513,32 @@
 )%0A              
-  
 .setDefault(Even
@@ -2576,26 +2576,24 @@
             
- 
- 
 EventEnvelop
@@ -2606,48 +2606,11 @@
 vent
-Factory.createEvent(newUuidValue())
 ))%0A
-  
     
@@ -2678,26 +2678,24 @@
             
-  
 RejectionEnv
@@ -2707,53 +2707,20 @@
 .of(
-c
 re
-ateRe
 jection
-(newUuidValue(), command)
 ))%0A
-  
     
@@ -2794,72 +2794,8 @@
 ss))
-%0A                .testAllPublicStaticMethods(PmDispatcher.class)
 ;%0A  

Simplify test