Skip to content

Commit

Permalink
added some new unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Frisch12 committed Jun 17, 2022
1 parent 4cf5748 commit e91c91f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -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'
}
}
Expand Down
1 change: 1 addition & 0 deletions plantuml-plugin/build.gradle
Expand Up @@ -8,6 +8,7 @@ dependencies {
//noinspection GradlePackageUpdate
compileOnly 'net.sourceforge.plantuml:plantuml:1.2022.5'

testImplementation 'net.sourceforge.plantuml:plantuml:1.2022.5'
}

gradlePlugin {
Expand Down
@@ -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 {

Expand All @@ -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<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;
}
};
}
};

action.execute();
}
}
6 changes: 6 additions & 0 deletions plantuml-plugin/src/test/resources/puml-files/test.puml
@@ -0,0 +1,6 @@
@startuml

Bob -> Alice: Test
Alice --> Bob: return Test

@enduml

0 comments on commit e91c91f

Please sign in to comment.