package co.com.bancolombia.task;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.task.ValidateStructureTask;
import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;

public class ValidateStructureTaskTest {

    ValidateStructureTask task;

    @Before
    public void init() throws IOException, CleanException {
        File projectDir = new File("build/unitTest");
        Files.createDirectories(projectDir.toPath());
        writeString(new File(projectDir, "settings.gradle"), "");
        writeString(new File(projectDir, "build.gradle"),
                "plugins {" +
                        "  id('co.com.bancolombia.cleanArchitecture')" +
                        "}");

        Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build();
        project.getTasks().create("testStructure", GenerateStructureTask.class);

        GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("testStructure");
        taskStructure.generateStructureTask();

        project.getTasks().create("test", ValidateStructureTask.class);
        task = (ValidateStructureTask) project.getTasks().getByName("test");
    }

    @Test
    public void validateStructure() throws IOException, CleanException {
        // Act
        task.validateStructureTask();
        // Assert
    }


    private void writeString(File file, String string) throws IOException {
        try (Writer writer = new FileWriter(file)) {
            writer.write(string);
        }
    }
}