@@ -0,0 +1,3012 @@
+/*%0A * Copyright 2020, TeamDev. All rights reserved.%0A *%0A * Redistribution and use in source and/or binary forms, with or without%0A * modification, must retain the above copyright notice and the following%0A * disclaimer.%0A *%0A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS%0A * %22AS IS%22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT%0A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR%0A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT%0A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,%0A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT%0A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,%0A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY%0A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT%0A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE%0A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A */%0A%0Apackage io.spine.testing.server.blackbox;%0A%0Aimport io.spine.server.BoundedContext;%0Aimport io.spine.server.BoundedContextBuilder;%0Aimport org.junit.jupiter.api.AfterEach;%0Aimport org.junit.jupiter.api.BeforeEach;%0Aimport org.junit.jupiter.api.DisplayName;%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport java.lang.annotation.Annotation;%0Aimport java.lang.reflect.Method;%0A%0Aimport static com.google.common.truth.Truth.assertThat;%0Aimport static org.junit.jupiter.api.Assertions.assertThrows;%0A%0A@DisplayName(%22%60ContextAwareTest%60 should%22)%0Aclass ContextAwareTestTest %7B%0A%0A    private final ContextAwareTest test = new DummyTest();%0A%0A    @Test%0A    @DisplayName(%22create a new context before each test%22)%0A    void createContext() throws NoSuchMethodException %7B%0A        assertAnnotated(%22createContext%22, BeforeEach.class);%0A%0A        // Assert that the context is not yet created.%0A        assertThrows(NullPointerException.class, test::context);%0A%0A        test.createContext();%0A        assertThat(test.context())%0A                .isNotNull();%0A    %7D%0A%0A    @Test%0A    @DisplayName(%22close and dispose context after each test%22)%0A    void closeContext() throws NoSuchMethodException %7B%0A        assertAnnotated(%22closeContext%22, AfterEach.class);%0A%0A        // Create the context so that we have a valid instance to close.%0A        test.createContext();%0A%0A        test.closeContext();%0A        assertThrows(NullPointerException.class, test::context);%0A    %7D%0A%0A    private static %3CT extends Annotation%3E%0A    void assertAnnotated(String methodName, Class%3CT%3E annotationClass)%0A            throws NoSuchMethodException %7B%0A        Method method = ContextAwareTest.class.getDeclaredMethod(methodName);%0A        Annotation annotation = method.getAnnotation(annotationClass);%0A        assertThat(annotation).isNotNull();%0A    %7D%0A%0A    private static class DummyTest extends ContextAwareTest %7B%0A%0A        @Override%0A        protected BoundedContextBuilder contextBuilder() %7B%0A            return BoundedContext.singleTenant(getClass().getSimpleName());%0A        %7D%0A    %7D%0A%7D%0A

Test `ContextAwareTest`