/*
 * 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.tools.gradle.testing;

import com.google.common.collect.ImmutableSet;
import io.spine.tools.gradle.Artifact;
import io.spine.tools.gradle.Dependency;
import io.spine.tools.gradle.ThirdPartyDependency;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

@DisplayName("MemoizingDependant should")
class MemoizingDependantTest {

    private MemoizingDependant container;

    @BeforeEach
    void setUp() {
        container = new MemoizingDependant();
    }

    @Test
    @DisplayName("memoize a given dependency")
    void addDependency() {
        Artifact dependency = artifact();
        container.implementation(dependency.notation());

        checkDependency(dependency);
    }

    @Test
    @DisplayName("memoize a given exclusion rule")
    void addExclusion() {
        Dependency unwanted = dependency();
        container.exclude(unwanted);

        checkExcluded(unwanted);
    }

    private void checkDependency(Artifact dependency) {
        ImmutableSet<String> dependencies = container.dependencies();
        assertThat(dependencies).contains(dependency.notation());
    }

    private void checkExcluded(Dependency unwanted) {
        ImmutableSet<Dependency> exclusions = container.exclusions();
        assertThat(exclusions).contains(unwanted);
    }

    private static Dependency dependency() {
        return new ThirdPartyDependency("test.dependency", "test-dependency");
    }

    private static Artifact artifact() {
        return dependency().ofVersion("3.14");
    }
}

@@ -1046,16 +1046,63 @@
 sting;%0A%0A
+import com.google.common.collect.ImmutableMap;%0A
 import c
@@ -2081,32 +2081,653 @@
 wanted);%0A    %7D%0A%0A
+    @Test%0A    @DisplayName(%22memoize a forced dependency%22)%0A    void addForcedDependency() %7B%0A        Dependency dependency = dependency();%0A        String version = version();%0A        container.force(dependency, version);%0A%0A        checkForced(dependency, version);%0A    %7D%0A%0A    @Test%0A    @DisplayName(%22remove memoized forced dependency%22)%0A    void removeForcedDependency() %7B%0A        Dependency dependency = dependency();%0A        String version = version();%0A        container.force(dependency, version);%0A%0A        container.removeForcedDependency(dependency);%0A        assertThat(container.forcedDependencies()).isEmpty();%0A    %7D%0A%0A
     private void
@@ -3083,32 +3083,280 @@
 wanted);%0A    %7D%0A%0A
+    private void checkForced(Dependency dependency, String version) %7B%0A        ImmutableMap%3CDependency, String%3E forcedDependencies = container.forcedDependencies();%0A        assertThat(forcedDependencies).containsExactly(dependency, version);%0A    %7D%0A%0A
     private stat
@@ -3462,32 +3462,100 @@
 dency%22);%0A    %7D%0A%0A
+    private static String version() %7B%0A        return %223.14%22;%0A    %7D%0A%0A
     private stat
@@ -3617,22 +3617,25 @@
 Version(
-%223.14%22
+version()
 );%0A    %7D

Add test for `MemoizingDependant` storing forced dependencies