Skip to content

Commit

Permalink
Convert tests to JUnit 5 and some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Jun 22, 2024
1 parent f496a85 commit a7a878a
Show file tree
Hide file tree
Showing 21 changed files with 321 additions and 328 deletions.
30 changes: 23 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.8.0</version>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -127,19 +127,35 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.35</version>
<version>1.37</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.35</version>
<version>1.37</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private boolean matches(String token, String pattern) {
boolean matches;

// support full wildcard and implied wildcard
if ("*".equals(pattern) || pattern.length() == 0) {
if ("*".equals(pattern) || pattern.isEmpty()) {
matches = true;
}
// support contains wildcard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public void reportMissedCriteria(Logger logger) {
report = true;
}

if (report && logger.isDebugEnabled()) {
logger.debug("The following scope filters were not used: " + buffer);
if (report) {
logger.debug("The following scope filters were not used: {}", buffer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,25 @@ public org.apache.maven.model.Dependency getDependency() {
mavenDependency.setOptional(nodeDependency.isOptional());
}
if (nodeDependency.getExclusions() != null) {
List<org.apache.maven.model.Exclusion> mavenExclusions =
new ArrayList<>(nodeDependency.getExclusions().size());
mavenDependency.setExclusions(getExclusions(nodeDependency));
}

return mavenDependency;
}

for (Exclusion aetherExclusion : nodeDependency.getExclusions()) {
org.apache.maven.model.Exclusion mavenExclusion = new org.apache.maven.model.Exclusion();
private static List<org.apache.maven.model.Exclusion> getExclusions(Dependency nodeDependency) {
List<org.apache.maven.model.Exclusion> mavenExclusions =
new ArrayList<>(nodeDependency.getExclusions().size());

mavenExclusion.setGroupId(aetherExclusion.getGroupId());
mavenExclusion.setArtifactId(aetherExclusion.getArtifactId());
// that's all folks, although Aether has more metadata
for (Exclusion aetherExclusion : nodeDependency.getExclusions()) {
org.apache.maven.model.Exclusion mavenExclusion = new org.apache.maven.model.Exclusion();

mavenExclusions.add(mavenExclusion);
}
mavenExclusion.setGroupId(aetherExclusion.getGroupId());
mavenExclusion.setArtifactId(aetherExclusion.getArtifactId());
// that's all folks, although Aether has more metadata

mavenDependency.setExclusions(mavenExclusions);
mavenExclusions.add(mavenExclusion);
}

return mavenDependency;
return mavenExclusions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -41,7 +41,7 @@ public abstract class AbstractPatternArtifactFilterTest {
protected abstract boolean isInclusionNotExpected();

@Test
public void testShouldTriggerBothPatternsWithWildcards() {
public void shouldTriggerBothPatternsWithWildcards() {
final String groupId1 = "group";
final String artifactId1 = "artifact";

Expand Down Expand Up @@ -76,7 +76,7 @@ public void testShouldTriggerBothPatternsWithWildcards() {
}

@Test
public void testShouldTriggerBothPatternsWithNonColonWildcards() {
public void shouldTriggerBothPatternsWithNonColonWildcards() {
final String groupId1 = "group";
final String artifactId1 = "artifact";

Expand Down Expand Up @@ -111,7 +111,7 @@ public void testShouldTriggerBothPatternsWithNonColonWildcards() {
}

@Test
public void testShouldIncludeDirectlyMatchedArtifactByGroupIdArtifactId() {
public void shouldIncludeDirectlyMatchedArtifactByGroupIdArtifactId() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -131,7 +131,7 @@ public void testShouldIncludeDirectlyMatchedArtifactByGroupIdArtifactId() {
}

@Test
public void testShouldIncludeDirectlyMatchedArtifactByDependencyConflictId() {
public void shouldIncludeDirectlyMatchedArtifactByDependencyConflictId() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -151,7 +151,7 @@ public void testShouldIncludeDirectlyMatchedArtifactByDependencyConflictId() {
}

@Test
public void testShouldNotIncludeWhenGroupIdDiffers() {
public void shouldNotIncludeWhenGroupIdDiffers() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -175,7 +175,7 @@ public void testShouldNotIncludeWhenGroupIdDiffers() {
}

@Test
public void testShouldNotIncludeWhenArtifactIdDiffers() {
public void shouldNotIncludeWhenArtifactIdDiffers() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -199,7 +199,7 @@ public void testShouldNotIncludeWhenArtifactIdDiffers() {
}

@Test
public void testShouldNotIncludeWhenBothIdElementsDiffer() {
public void shouldNotIncludeWhenBothIdElementsDiffer() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -223,7 +223,7 @@ public void testShouldNotIncludeWhenBothIdElementsDiffer() {
}

@Test
public void testShouldIncludeWhenPatternMatchesDependencyTrailAndTransitivityIsEnabled() {
public void shouldIncludeWhenPatternMatchesDependencyTrailAndTransitivityIsEnabled() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -250,7 +250,7 @@ public void testShouldIncludeWhenPatternMatchesDependencyTrailAndTransitivityIsE
}

@Test
public void testIncludeWhenPatternMatchesDepTrailWithTransitivityUsingNonColonWildcard() {
public void shouldIncludeWhenPatternMatchesDepTrailWithTransitivityUsingNonColonWildcard() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -277,7 +277,7 @@ public void testIncludeWhenPatternMatchesDepTrailWithTransitivityUsingNonColonWi
}

@Test
public void testShouldNotIncludeWhenNegativeMatch() {
public void shouldNotIncludeWhenNegativeMatch() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -300,7 +300,7 @@ public void testShouldNotIncludeWhenNegativeMatch() {
}

@Test
public void testShouldIncludeWhenWildcardMatchesInsideSequence() {
public void shouldIncludeWhenWildcardMatchesInsideSequence() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -323,7 +323,7 @@ public void testShouldIncludeWhenWildcardMatchesInsideSequence() {
}

@Test
public void testShouldIncludeWhenWildcardMatchesOutsideSequence() {
public void shouldIncludeWhenWildcardMatchesOutsideSequence() {
final String groupId = "group";
final String artifactId = "artifact";

Expand All @@ -347,7 +347,7 @@ public void testShouldIncludeWhenWildcardMatchesOutsideSequence() {
}

@Test
public void testShouldIncludeWhenWildcardMatchesMiddleOfArtifactId() {
public void shouldIncludeWhenWildcardMatchesMiddleOfArtifactId() {
final String groupId = "group";
final String artifactId = "some-artifact-id";

Expand All @@ -371,7 +371,7 @@ public void testShouldIncludeWhenWildcardMatchesMiddleOfArtifactId() {
}

@Test
public void testShouldIncludeWhenWildcardCoversPartOfGroupIdAndEverythingElse() {
public void shouldIncludeWhenWildcardCoversPartOfGroupIdAndEverythingElse() {
final String groupId = "some.group.id";
final String artifactId = "some-artifact-id";

Expand All @@ -395,7 +395,7 @@ public void testShouldIncludeWhenWildcardCoversPartOfGroupIdAndEverythingElse()
}

@Test
public void testShouldIncludeTransitiveDependencyWhenWildcardMatchesButDoesntMatchParent() {
public void shouldIncludeTransitiveDependencyWhenWildcardMatchesButDoesntMatchParent() {
final String groupId = "group";
final String artifactId = "artifact";

Expand Down Expand Up @@ -430,7 +430,7 @@ public void testShouldIncludeTransitiveDependencyWhenWildcardMatchesButDoesntMat
}

@Test
public void testShouldIncludeJarsWithAndWithoutClassifier() {
public void shouldIncludeJarsWithAndWithoutClassifier() {
final String groupId = "com.mycompany.myproject";
final String artifactId = "some-artifact-id";

Expand All @@ -453,7 +453,7 @@ public void testShouldIncludeJarsWithAndWithoutClassifier() {
}

@Test
public void testWithVersionRange() {
public void checkWithVersionRange() {
final String groupId = "com.mycompany.myproject";
final String artifactId = "some-artifact-id";

Expand All @@ -476,7 +476,7 @@ public void testWithVersionRange() {
}

@Test
public void testmassembly955() {
public void checkMassembly955() {
Artifact artifact1 = mock(Artifact.class);
when(artifact1.getGroupId()).thenReturn("org.python");
when(artifact1.getArtifactId()).thenReturn("jython-standalone");
Expand Down Expand Up @@ -507,7 +507,7 @@ public void testmassembly955() {
}

@Test
public void testPartialWildcardShouldNotMatchEmptyComponent() {
public void partialWildcardShouldNotMatchEmptyComponent() {
Artifact artifact = mock(Artifact.class);
when(artifact.getGroupId()).thenReturn("test-group");
when(artifact.getArtifactId()).thenReturn("test-artifact");
Expand Down
Loading

0 comments on commit a7a878a

Please sign in to comment.