Skip to content

Commit

Permalink
cleanup test
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgrefer committed Jun 17, 2022
1 parent 4e52447 commit 4a5ac9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion plantuml-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,19 +17,22 @@

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");
}

@Test
void execute() {
Project project = ProjectBuilder.builder().build();

project.getPlugins().apply(PlantumlPlugin.class);

PlantumlTask task = project.getTasks().withType(PlantumlTask.class).getByName("plantUml");
Expand All @@ -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<String> getFileFormat() {
Property<String> property = project.getObjects().property(String.class);
property.set("PNG");
return property;
}

@Override
public Property<Boolean> getWithMetadata() {
Property<Boolean> property = project.getObjects().property(Boolean.class);
property.set(false);
return property;
}
};
return parameters;
}
};

Expand Down

0 comments on commit 4a5ac9d

Please sign in to comment.