Skip to content

Commit

Permalink
Use assertj-gradle in unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
baron1405 committed Dec 25, 2024
1 parent d03d189 commit 3a0fce6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies {
compileOnly(libs.cthingAnnots)

testImplementation(libs.assertJ)
testImplementation(libs.assertJGradle)
testImplementation(libs.commonsIO)
testImplementation(libs.jacksonCoreUtils)
testImplementation(libs.jacksonCore)
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ versions = { id = "com.github.ben-manes.versions", version = "0.51.0" }

[libraries]
assertJ = "org.assertj:assertj-core:3.26.3"
assertJGradle = "org.cthing:assertj-gradle:1.0.0"
commonsIO = "commons-io:commons-io:2.18.0"
cthingAnnots = "org.cthing:cthing-annotations:2.0.0"
escapers = "org.cthing:escapers:2.0.0"
Expand Down
18 changes: 10 additions & 8 deletions src/test/java/org/cthing/gradle/plugins/locc/PluginApplyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import javax.xml.transform.stream.StreamSource;

import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.xmlunit.validation.Languages;
import org.xmlunit.validation.Validator;

Expand All @@ -25,20 +25,20 @@
import com.github.fge.jsonschema.processors.syntax.SyntaxValidator;

import static org.assertj.core.api.Assertions.assertThat;
import static org.cthing.assertj.gradle.GradleProjectAssert.assertThat;


@SuppressWarnings("DataFlowIssue")
public class PluginApplyTest {

@Test
public void testApply(@TempDir final File projectDir) {
final Project project = ProjectBuilder.builder().withName("testProject").withProjectDir(projectDir).build();
public void testApply() {
final Project project = ProjectBuilder.builder().build();
project.getPluginManager().apply("org.cthing.locc");

assertThat(project.getExtensions().findByName(LoccPlugin.EXTENSION_NAME)).isInstanceOf(LoccExtension.class);
assertThat(project).hasExtensionWithType(LoccPlugin.EXTENSION_NAME, LoccExtension.class);

final Task task = project.getTasks().findByName(LoccPlugin.TASK_NAME);
assertThat(task).isNotNull().isInstanceOf(LoccTask.class);
assertThat(project).hasTaskWithReports(LoccPlugin.TASK_NAME);
final Task task = project.getTasks().getByName(LoccPlugin.TASK_NAME);
final LoccReports reports = ((LoccTask)task).getReports();
assertThat(reports.getXml().getRequired().get()).isTrue();
assertThat(reports.getHtml().getRequired().get()).isTrue();
Expand All @@ -61,7 +61,9 @@ public void testXmlSchema() throws IOException {
public void testJsonSchema() throws IOException {
final JsonSchemaFactory schemaFactory = JsonSchemaFactory.byDefault();
final SyntaxValidator validator = schemaFactory.getSyntaxValidator();
final File schema = new File(getClass().getResource("/org/cthing/gradle/plugins/locc/locc-1.json").getPath());
final URL resourceUrl = getClass().getResource("/org/cthing/gradle/plugins/locc/locc-1.json");
assertThat(resourceUrl).isNotNull();
final File schema = new File(resourceUrl.getPath());
final JsonNode rootNode = JsonLoader.fromFile(schema);
assertThat(validator.validateSchema(rootNode).isSuccess()).isTrue();
}
Expand Down

0 comments on commit 3a0fce6

Please sign in to comment.