/*
 * 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.compiler;

import com.google.common.collect.ImmutableList;
import io.spine.tools.gradle.GradleProject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.TempDirectory;

import java.io.File;
import java.nio.file.Path;

import static io.spine.tools.gradle.TaskName.COMPILE_JAVA;

@ExtendWith(TempDirectory.class)
@DisplayName("ValidatingBuilderGenPlugin should")
class ValidatingBuilderGenPluginTest {

    /**
     * The name of the directory under `test/resource` which will be used for creating
     * the test project.
     */
    private static final String PROJECT_NAME = "validators-gen-plugin-test";

    /**
     * Names of resource files under the resources "root".
     */
    private static final ImmutableList<String> PROTO_FILES =
            ImmutableList.of("identifiers.proto",
                             "attributes.proto",
                             "changes.proto",
                             "test_commands.proto");

    private File testProjectDir;

    @BeforeEach
    void setUp(@TempDirectory.TempDir Path tempDirPath) {
        testProjectDir = tempDirPath.toFile();
    }

    @Test
    @DisplayName("compile generated validators")
    void compileGeneratedValidators() {
        GradleProject project =
                GradleProject.newBuilder()
                             .setProjectName(PROJECT_NAME)
                             .setProjectFolder(testProjectDir)
                             .addProtoFiles(PROTO_FILES)
                             .build();
        project.executeTask(COMPILE_JAVA);
    }
}

@@ -1139,16 +1139,147 @@
 roject;%0A
+import io.spine.tools.gradle.TaskName;%0Aimport org.gradle.testkit.runner.BuildResult;%0Aimport org.gradle.testkit.runner.TaskOutcome;%0A
 import o
@@ -1536,16 +1536,72 @@
 .Path;%0A%0A
+import static com.google.common.truth.Truth.assertThat;%0A
 import s
@@ -1650,16 +1650,216 @@
 LE_JAVA;
+%0Aimport static io.spine.tools.gradle.TaskName.GENERATE_VALIDATING_BUILDERS;%0Aimport static org.gradle.testkit.runner.TaskOutcome.SUCCESS;%0Aimport static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE;
 %0A%0A@Exten
@@ -2773,24 +2773,772 @@
 idators() %7B%0A
+        GradleProject project = newProject();%0A        project.executeTask(COMPILE_JAVA);%0A    %7D%0A%0A    @Test%0A    @DisplayName(%22skip task if inputs and outputs stay the same%22)%0A    void incremental() %7B%0A        GradleProject project = newProject();%0A%0A        TaskName taskName = GENERATE_VALIDATING_BUILDERS;%0A        BuildResult firstRun = project.executeTask(taskName);%0A        TaskOutcome firstOutcome = firstRun.task(taskName.path()).getOutcome();%0A        assertThat(firstOutcome).isEqualTo(SUCCESS);%0A%0A        BuildResult secondRun = project.executeTask(taskName);%0A        TaskOutcome secondOutcome = secondRun.task(taskName.path()).getOutcome();%0A        assertThat(secondOutcome).isEqualTo(UP_TO_DATE);%0A    %7D%0A%0A    private GradleProject newProject() %7B%0A
         Grad
@@ -3813,58 +3813,83 @@
    .
-build();%0A        project.executeTask(COMPILE_JAVA)
+enableDebug()%0A                             .build();%0A        return project
 ;%0A  

Add a test for incremental build.