/*
 * 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.base.RejectionMessage;
import io.spine.core.Event;
import io.spine.server.type.given.rejection.PhoneNotFound;
import io.spine.server.type.given.rejection.TestRejections;
import io.spine.server.type.given.rejection.UnableToLocateKeys;
import io.spine.testing.core.given.GivenUserId;
import io.spine.testing.server.TestEventFactory;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static com.google.common.truth.Truth.assertThat;
import static io.spine.server.type.RejectionClass.from;
import static io.spine.server.type.RejectionClass.of;
import static io.spine.testing.DisplayNames.NOT_ACCEPT_NULLS;

@DisplayName("`RejectionClass` should")
class RejectionClassTest {

    /** Test value for test data rejections. */
    private final String user = GivenUserId.generated().getValue();

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

    @Test
    @DisplayName("obtain the value by the `RejectionMessage` class")
    void byClass() {
        Class<TestRejections.PhoneNotFound> expected = TestRejections.PhoneNotFound.class;
        assertThat(of(expected).value())
                .isEqualTo(expected);
    }

    @Test
    @DisplayName("obtain the value by rejection message")
    void byMessage() {
        RejectionMessage msg =
                PhoneNotFound.newBuilder()
                             .setUser(user)
                             .build()
                             .messageThrown();
        assertThat(of(msg).value())
                .isEqualTo(msg.getClass());
    }

    @Test
    @DisplayName("obtain the value by the `Event` instance")
    void byEvent() {
        RejectionMessage msg = UnableToLocateKeys
                .newBuilder()
                .setUser(user)
                .build()
                .messageThrown();
        Event event = TestEventFactory.newInstance(getClass())
                                      .createEvent(msg);

        assertThat(of(event).value())
                .isEqualTo(msg.getClass());
    }

    @Test
    @DisplayName("obtain the value by `ThrowableMessage` class")
    void byThrowableMessage() {
        assertThat(from(PhoneNotFound.class).value())
                .isEqualTo(TestRejections.PhoneNotFound.class);
    }
}

@@ -1810,16 +1810,142 @@
 Test %7B%0A%0A
+    private static final TestEventFactory eventFactory =%0A            TestEventFactory.newInstance(RejectionClassTest.class);%0A%0A
     /** 
@@ -3182,21 +3182,17 @@
 event = 
-TestE
+e
 ventFact
@@ -3198,71 +3198,8 @@
 tory
-.newInstance(getClass())%0A                                      
 .cre

Test obtaining rejection class