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

import io.spine.server.event.model.given.reactor.RcIterableReturn;
import io.spine.server.event.model.given.reactor.RcOneParam;
import io.spine.server.event.model.given.reactor.RcReturnOptional;
import io.spine.server.event.model.given.reactor.RcTwoParams;
import io.spine.server.event.model.given.reactor.RcWrongAnnotation;
import io.spine.server.event.model.given.reactor.RcWrongNoAnnotation;
import io.spine.server.event.model.given.reactor.RcWrongNoParam;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
import java.util.function.Predicate;

import static com.google.common.truth.Truth.assertThat;

/**
 * @author Alexander Yevsyukov
 */
@SuppressWarnings("InnerClassMayBeStatic")
@DisplayName("EventReactorMethod should")
class EventReactorMethodTest {

    private static final Predicate<Method> predicate = EventReactorMethod.factory().getPredicate();

    @Nested
    @DisplayName("consider reactor method valid with")
    class MethodArguments {

        @Test
        @DisplayName("one event message parameter")
        void oneParam() {
            Method method = new RcOneParam().getMethod();
            assertValid(method, true);
        }

        @Test
        @DisplayName("event message and context")
        void twoParams() {
            Method method = new RcTwoParams().getMethod();
            assertValid(method, true);
        }


        @Test
        @DisplayName("Iterable return value")
        void iterableReturn() {
            Method method = new RcIterableReturn().getMethod();
            assertValid(method, true);
        }

        @Test
        @DisplayName("Optional return value")
        void optionalReturn() {
            Method method = new RcReturnOptional().getMethod();
            assertValid(method, true);
        }
    }

    @Nested
    @DisplayName("consider a method invalid if")
    class NotReactor {

        @Test
        @DisplayName("no annotation is provided")
        void noAnnotation() {
            Method method = new RcWrongNoAnnotation().getMethod();
            assertValid(method, false);
        }

        @Test
        @DisplayName("wrong annotations provided")
        void wrongAnnotations() {
            Method method = new RcWrongAnnotation().getMethod();
            assertValid(method, false);
        }

        @Test
        @DisplayName("it has no parameters")
        void noParameters() {
            Method method = new RcWrongNoParam().getMethod();
            assertValid(method, false);
        }
    }

    private static void assertValid(Method reactor, boolean isReactor) {
        assertThat(predicate.test(reactor)).isEqualTo(isReactor);
    }
}

@@ -2004,16 +2004,162 @@
 ate();%0A%0A
+    private static void assertValid(Method reactor, boolean isReactor) %7B%0A        assertThat(predicate.test(reactor)).isEqualTo(isReactor);%0A    %7D%0A%0A
     @Nes
@@ -2645,16 +2645,291 @@
       %7D%0A
+    %7D%0A%0A    @Nested%0A    @DisplayName(%22allow return value of type%22)%0A    class ReturnValues %7B%0A%0A        @Test%0A        @DisplayName(%22Message%22)%0A        void messageReturn() %7B%0A            Method method = new RcOneParam().getMethod();%0A            assertValid(method, true);%0A        %7D
 %0A%0A      
@@ -2966,29 +2966,16 @@
 Iterable
- return value
 %22)%0A     
@@ -3159,29 +3159,16 @@
 Optional
- return value
 %22)%0A     
@@ -4036,153 +4036,7 @@
    %7D
-%0A%0A    private static void assertValid(Method reactor, boolean isReactor) %7B%0A        assertThat(predicate.test(reactor)).isEqualTo(isReactor);%0A    %7D
 %0A%7D%0A

Test return types in a separate nested class