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 499ed1b commit d687c56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies {
compileOnly(libs.cthingAnnots)

testImplementation(libs.assertJ)
testImplementation(libs.assertJGradle)
testImplementation(libs.commonsIO)
testImplementation(libs.junitApi)
testImplementation(libs.junitParams)
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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"
jspecify = "org.jspecify:jspecify:1.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.stream.Stream;

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;
Expand All @@ -18,6 +17,7 @@
import org.junit.jupiter.params.provider.MethodSource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.cthing.assertj.gradle.GradleProjectAssert.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;


Expand All @@ -28,21 +28,19 @@ public void testApply(@TempDir final File projectDir) {
final Project project = ProjectBuilder.builder().withName("testProject").withProjectDir(projectDir).build();
project.getPluginManager().apply("org.cthing.property-key-constants");

final Object extensionObj = project.getExtensions().findByName(PropertyKeyConstantsPlugin.EXTENSION_NAME);
assertThat(extensionObj).isNotNull();
assertThat(extensionObj).isInstanceOf(PropertyKeyConstantsExtension.class);
assertThat(project).hasExtensionWithType(PropertyKeyConstantsPlugin.EXTENSION_NAME,
PropertyKeyConstantsExtension.class);

final PropertyKeyConstantsExtension extension = (PropertyKeyConstantsExtension)extensionObj;
final PropertyKeyConstantsExtension extension =
(PropertyKeyConstantsExtension)project.getExtensions().getByName(PropertyKeyConstantsPlugin.EXTENSION_NAME);
assertThat(extension.getSourceAccess().get()).isEqualTo(SourceAccess.PUBLIC);
assertThat(extension.getSourceLayout().get()).isEqualTo(SourceLayout.NESTED_CLASSES);

final Task mainTask = project.getTasks().findByName("generatePropertyKeyConstants");
assertThat(mainTask).isNotNull().isInstanceOf(PropertyKeyConstantsTask.class);
assertThat(project).hasTaskWithType("generatePropertyKeyConstants", PropertyKeyConstantsTask.class);
assertThat(project).hasTaskWithType("generateTestPropertyKeyConstants", PropertyKeyConstantsTask.class);

final Task testTask = project.getTasks().findByName("generateTestPropertyKeyConstants");
assertThat(testTask).isNotNull().isInstanceOf(PropertyKeyConstantsTask.class);

final PropertyKeyConstantsTask task = (PropertyKeyConstantsTask)mainTask;
final PropertyKeyConstantsTask task =
(PropertyKeyConstantsTask)project.getTasks().getByName("generatePropertyKeyConstants");
assertThat(task.getClassname().isPresent()).isFalse();
assertThat(task.getOutputDirectory().get().getAsFile().getPath())
.endsWith("build/generated-src/property-key-constants/main");
Expand Down

0 comments on commit d687c56

Please sign in to comment.