diff --git a/build.gradle b/build.gradle index 05d4d289..e7b66bad 100644 --- a/build.gradle +++ b/build.gradle @@ -60,6 +60,7 @@ allprojects { testImplementation 'org.assertj:assertj-core:3.23.1' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2' + testImplementation 'org.mockito:mockito-core:4.6.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' } } diff --git a/plantuml-plugin/build.gradle b/plantuml-plugin/build.gradle index c799a912..8f6a126f 100644 --- a/plantuml-plugin/build.gradle +++ b/plantuml-plugin/build.gradle @@ -8,6 +8,7 @@ dependencies { //noinspection GradlePackageUpdate compileOnly 'net.sourceforge.plantuml:plantuml:1.2022.5' + testImplementation '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 2def7940..9f5bcc68 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 @@ -1,11 +1,16 @@ package io.freefair.gradle.plugins.plantuml; import org.gradle.api.Project; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; import org.gradle.testfixtures.ProjectBuilder; import org.junit.jupiter.api.Test; +import java.io.File; + import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertThrows; class PlantumlPluginTest { @@ -17,4 +22,59 @@ void apply() { assertThat(project.getTasks().getNames()).contains("plantUml"); } + + @Test + void execute() { + Project project = ProjectBuilder.builder().build(); + + project.getPlugins().apply(PlantumlPlugin.class); + + PlantumlTask task = project.getTasks().withType(PlantumlTask.class).getByName("plantUml"); + + task.source(getClass().getClassLoader().getResource("puml-files").getPath()); + + assertThrows(UnsupportedOperationException.class, task::execute); + } + + @Test + void taskExecution() { + Project project = ProjectBuilder.builder().build(); + + 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; + } + }; + } + }; + + action.execute(); + } } diff --git a/plantuml-plugin/src/test/resources/puml-files/test.puml b/plantuml-plugin/src/test/resources/puml-files/test.puml new file mode 100644 index 00000000..f9740ee8 --- /dev/null +++ b/plantuml-plugin/src/test/resources/puml-files/test.puml @@ -0,0 +1,6 @@ +@startuml + +Bob -> Alice: Test +Alice --> Bob: return Test + +@enduml \ No newline at end of file