@@ -0,0 +1,3331 @@
+/*%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.base.CommandMessage;%0Aimport io.spine.server.BoundedContextBuilder;%0Aimport org.checkerframework.checker.nullness.qual.Nullable;%0Aimport org.junit.jupiter.api.AfterEach;%0Aimport org.junit.jupiter.api.BeforeEach;%0A%0Aimport static com.google.common.base.Preconditions.checkNotNull;%0A%0A/**%0A * Abstract base for test suites based on %7B@link BlackBoxBoundedContext%7D.%0A *%0A * %3Cp%3ESuch a test suite creates a new instance of %7B@link io.spine.server.BoundedContext%0A * BoundedContext%7D using a builder which implementing classes must %7B@linkplain #contextBuilder()%0A * provide%7D. The context under the test is created %7B@linkplain BeforeEach before each%7D test method%0A * and closed %7B@linkplain AfterEach after each%7D test method automatically.%0A *%0A * %3Cp%3ETesting methods %7B@linkplain #context() obtain the context%7D for:%0A * %3Col%3E%0A *     %3Cli%3ESending signals under the test to the context via %7B@code receivesXxx()%7D methods, such as%0A *         %7B@link BlackBoxBoundedContext#receivesCommand(CommandMessage) receivesCommand()%7D.%0A *     %3Cli%3EAsserting results of handling the signals via %7B@code assertXxx()%7D methods,%0A *     e.g. %7B@link BlackBoxBoundedContext#assertEvents() assertEvents()%7D.%0A * %3C/ol%3E%0A *%0A * %3Cp%3ETest suites derived from this class must NOT close the context directly. Doing so will fail%0A * the test.%0A */%0Apublic abstract class ContextAwareTest %7B%0A%0A    private @Nullable BlackBoxBoundedContext%3C?%3E context;%0A%0A    /**%0A     * Creates a new builder for the Bounded Context under the test.%0A     */%0A    protected abstract BoundedContextBuilder contextBuilder();%0A%0A    @BeforeEach%0A    void createContext() %7B%0A        BoundedContextBuilder contextBuilder = contextBuilder();%0A        checkNotNull(contextBuilder,%0A                     %22%60contextBuilder()%60 must return a non-null %60BoundedContextBuilder%60.%22);%0A        context = BlackBoxBoundedContext.from(contextBuilder);%0A    %7D%0A%0A    @AfterEach%0A    void closeContext() %7B%0A        context().close();%0A        context = null;%0A    %7D%0A%0A    /**%0A     * Obtains test configuration and assertion API for the Bounded Context under the test.%0A     */%0A    protected BlackBoxBoundedContext%3C?%3E context() %7B%0A        return checkNotNull(%0A                context,%0A                %22The %60BoundedContext%60 under the test is already destroyed or not yet created.%22%0A        );%0A    %7D%0A%7D%0A

Introduce abstract context-aware test base