Skip to content

Commit

Permalink
GH-31 - Polishing.
Browse files Browse the repository at this point in the history
Added unit tests for the test execution conditions.

Add JUnit module to the BOM. Moved the jGit version into a managed property in the root pom.xml.
  • Loading branch information
odrotbohm committed Sep 8, 2024
1 parent beb5e0e commit 48fefc1
Show file tree
Hide file tree
Showing 29 changed files with 1,058 additions and 369 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<archunit.version>1.3.0</archunit.version>
<artifactory-maven-plugin.version>3.6.2</artifactory-maven-plugin.version>
<flapdoodle-mongodb.version>4.14.0</flapdoodle-mongodb.version>
<jgit.version>6.10.0.202406032230-r</jgit.version>
<jgrapht.version>1.5.2</jgrapht.version>
<jmolecules-bom.version>2023.1.4</jmolecules-bom.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
5 changes: 5 additions & 0 deletions spring-modulith-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
<artifactId>spring-modulith-events-tests</artifactId>
<version>1.3.0-GH-31-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-junit</artifactId>
<version>1.3.0-GH-31-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-moments</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-junit</artifactId>
<version>1.3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>
7 changes: 7 additions & 0 deletions spring-modulith-integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@

<!-- Test -->

<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-junit</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @author Oliver Drotbohm
* @author Peter Gafert
*/
class ModulithTest {
public class ModulithTest {

static final DescribedPredicate<JavaClass> DEFAULT_EXCLUSIONS = Filters.withoutModules("cycleA", "cycleB", "invalid2",
"invalid3", "fieldinjected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author Oliver Drotbohm
*/
@NonVerifyingModuleTest
class ModuleDTest {
public class ModuleDTest {

@Autowired ConfigurableApplicationContext context;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.modulith.junit;

import static org.assertj.core.api.Assertions.*;

import java.util.Arrays;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.springframework.modulith.junit.TestExecutionCondition.ConditionContext;
import org.springframework.modulith.junit.diff.ModifiedFile;

import com.acme.myproject.ModulithTest;
import com.acme.myproject.moduleD.ModuleDTest;

/**
* Unit tests for {@link TestExecutionCondition}.
*
* @author Oliver Drotbohm
*/
class TestExecutionConditionUnitTests {

TestExecutionCondition condition = new TestExecutionCondition();

@Test // GH-31
void enablesForSourceChangeInSameModulen() {
assertEnabled(ModuleDTest.class, "moduleD/SomeConfigurationD.java");
}

@Test // GH-31
void enablesForSourceChangeInModuleDirectlyDependedOn() {
assertEnabled(ModuleDTest.class, "moduleC/ServiceComponentC.java");
}

@Test // GH-31
void enablesForSourceChangeInModuleIndirectlyDependedOn() {
assertEnabled(ModuleDTest.class, "moduleB/ServiceComponentB.java");
}

@Test // GH-31
void disablesForChangesInUnrelatedModule() {
assertDisabled(ModuleDTest.class, "moduleB/ServiceComponentE.java");
}

@Test // GH-31
void enablesTestInRootModule() {
assertEnabled(ModulithTest.class);
}

@Test // GH-31
void enablesForClasspathFileChange() {

var pomXml = new ModifiedFile("pom.xml");

assertEnabled(ModuleDTest.class, true, Stream.of(pomXml));
}

private void assertEnabled(Class<?> type, String... files) {
assertEnabled(type, true, files);
}

private void assertDisabled(Class<?> type, String... files) {
assertEnabled(type, false, files);
}

private void assertEnabled(Class<?> type, boolean expected, String... files) {

var modifiedFiles = Arrays.stream(files)
.map("src/main/java/com/acme/myproject/"::concat)
.map(ModifiedFile::new);

assertEnabled(type, expected, modifiedFiles);
}

private void assertEnabled(Class<?> type, boolean expected, Stream<ModifiedFile> files) {

assertThat(condition.evaluate(new ConditionContext(type, Changes.of(files))))
.extracting(ConditionEvaluationResult::isDisabled)
.isNotEqualTo(expected);
}
}
4 changes: 2 additions & 2 deletions spring-modulith-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<relativePath>../pom.xml</relativePath>
</parent>

<name>Spring Modulith - Test Junit</name>
<name>Spring Modulith - JUnit Integration</name>

<artifactId>spring-modulith-junit</artifactId>

Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>6.8.0.202311291450-r</version>
<version>${jgit.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.modulith</groupId>
Expand Down

This file was deleted.

Loading

0 comments on commit 48fefc1

Please sign in to comment.