From 4a5ac9d7e405bb278d6d816e884269d1ebf1f2e1 Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Fri, 17 Jun 2022 23:10:11 +0200 Subject: [PATCH] cleanup test --- plantuml-plugin/build.gradle | 2 +- .../plugins/plantuml/PlantumlPluginTest.java | 53 +++++++------------ 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/plantuml-plugin/build.gradle b/plantuml-plugin/build.gradle index 8f6a126f..52a16c6b 100644 --- a/plantuml-plugin/build.gradle +++ b/plantuml-plugin/build.gradle @@ -8,7 +8,7 @@ dependencies { //noinspection GradlePackageUpdate compileOnly 'net.sourceforge.plantuml:plantuml:1.2022.5' - testImplementation 'net.sourceforge.plantuml:plantuml:1.2022.5' + testRuntimeOnly 'net.sourceforge.plantuml:plantuml:1.2022.5' } gradlePlugin { diff --git a/plantuml-plugin/src/test/java/io/freefair/gradle/plugins/plantuml/PlantumlPluginTest.java b/plantuml-plugin/src/test/java/io/freefair/gradle/plugins/plantuml/PlantumlPluginTest.java index 9f5bcc68..3d2e2a1b 100644 --- a/plantuml-plugin/src/test/java/io/freefair/gradle/plugins/plantuml/PlantumlPluginTest.java +++ b/plantuml-plugin/src/test/java/io/freefair/gradle/plugins/plantuml/PlantumlPluginTest.java @@ -4,8 +4,11 @@ import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.Property; +import org.gradle.internal.impldep.org.junit.Before; import org.gradle.testfixtures.ProjectBuilder; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; @@ -14,10 +17,15 @@ class PlantumlPluginTest { + private Project project; + + @BeforeEach + void init() { + project = ProjectBuilder.builder().build(); + } + @Test void apply() { - Project project = ProjectBuilder.builder().build(); - project.getPlugins().apply(PlantumlPlugin.class); assertThat(project.getTasks().getNames()).contains("plantUml"); @@ -25,8 +33,6 @@ void apply() { @Test void execute() { - Project project = ProjectBuilder.builder().build(); - project.getPlugins().apply(PlantumlPlugin.class); PlantumlTask task = project.getTasks().withType(PlantumlTask.class).getByName("plantUml"); @@ -37,41 +43,18 @@ void execute() { } @Test - void taskExecution() { - Project project = ProjectBuilder.builder().build(); + void taskExecution(@TempDir File tempDir) { + PlantumlParameters parameters = project.getObjects().newInstance(PlantumlParameters.class); + + parameters.getInputFile().set(new File(getClass().getClassLoader().getResource("puml-files/test.puml").getPath())); + parameters.getOutputDirectory().set(tempDir); + parameters.getFileFormat().set("PNG"); + parameters.getWithMetadata().set(false); PlantumlAction action = new PlantumlAction() { @Override public PlantumlParameters getParameters() { - return new PlantumlParameters() { - @Override - public RegularFileProperty getInputFile() { - RegularFileProperty result = project.getObjects().fileProperty(); - result.set(new File(getClass().getClassLoader().getResource("puml-files/test.puml").getPath())); - return result; - } - - @Override - public DirectoryProperty getOutputDirectory() { - DirectoryProperty result = project.getObjects().directoryProperty(); - result.set(new File(getClass().getClassLoader().getResource("puml-files").getPath())); - return result; - } - - @Override - public Property getFileFormat() { - Property property = project.getObjects().property(String.class); - property.set("PNG"); - return property; - } - - @Override - public Property getWithMetadata() { - Property property = project.getObjects().property(Boolean.class); - property.set(false); - return property; - } - }; + return parameters; } };