Skip to content

Commit 2e14a0a

Browse files
authored
More meaningful assertions (#1611)
* Simplify assertions * spotless
1 parent 3326f3d commit 2e14a0a

5 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/test/java/org/apache/maven/plugins/dependency/RemoveDependencyMojoTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
4040
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
41+
import static org.junit.jupiter.api.Assertions.assertEquals;
42+
import static org.junit.jupiter.api.Assertions.assertFalse;
4143
import static org.junit.jupiter.api.Assertions.assertThrows;
4244
import static org.junit.jupiter.api.Assertions.assertTrue;
4345
import static org.mockito.ArgumentMatchers.contains;
@@ -157,7 +159,7 @@ void typeParameterUsedForMatching() throws Exception {
157159
mojo.execute();
158160

159161
String result = new String(Files.readAllBytes(pomFile.toPath()), StandardCharsets.UTF_8);
160-
assertTrue(!result.contains("test-jar"), "test-jar variant should be removed");
162+
assertFalse(result.contains("test-jar"), "test-jar variant should be removed");
161163
assertTrue(result.contains("com.example"), "jar variant should remain");
162164
}
163165

@@ -205,7 +207,7 @@ void modelSyncPreservesOtherVariantsOnRemove() throws Exception {
205207
mojo.execute();
206208

207209
// In-memory model should still have the jar variant
208-
assertTrue(model.getDependencies().size() == 1, "model should have 1 dependency remaining");
210+
assertEquals(1, model.getDependencies().size(), "model should have 1 dependency remaining");
209211
assertTrue(
210212
"jar".equals(model.getDependencies().get(0).getType())
211213
|| model.getDependencies().get(0).getType() == null,
@@ -275,7 +277,7 @@ void removeDependencyFromProfileSucceeds() throws Exception {
275277
mojo.execute();
276278

277279
String result = new String(Files.readAllBytes(pomFile.toPath()), StandardCharsets.UTF_8);
278-
assertTrue(!result.contains("<groupId>com.example</groupId>"), "dependency should be removed");
280+
assertFalse(result.contains("<groupId>com.example</groupId>"), "dependency should be removed");
279281
assertTrue(result.contains("<id>dev</id>"), "profile should remain");
280282
}
281283

@@ -328,7 +330,7 @@ void managedRemovalWithChildModulesWarnsAndProceeds() throws Exception {
328330
assertDoesNotThrow(() -> mojo.execute());
329331

330332
String result = new String(Files.readAllBytes(pomFile.toPath()), StandardCharsets.UTF_8);
331-
assertTrue(!result.contains("<artifactId>lib</artifactId>"), "managed dep should be removed");
333+
assertFalse(result.contains("<artifactId>lib</artifactId>"), "managed dep should be removed");
332334
}
333335

334336
@Test
@@ -374,7 +376,7 @@ void managedRemovalWithChildModulePomPathWarnsAndProceeds() throws Exception {
374376
assertDoesNotThrow(() -> mojo.execute());
375377

376378
String result = new String(Files.readAllBytes(pomFile.toPath()), StandardCharsets.UTF_8);
377-
assertTrue(!result.contains("<artifactId>lib</artifactId>"), "managed dep should be removed");
379+
assertFalse(result.contains("<artifactId>lib</artifactId>"), "managed dep should be removed");
378380
verify(log).warn(contains("child-a/my-pom.xml"));
379381
}
380382

src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
import static org.junit.jupiter.api.Assertions.assertEquals;
3636
import static org.junit.jupiter.api.Assertions.assertFalse;
37+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
3738
import static org.junit.jupiter.api.Assertions.assertNotNull;
38-
import static org.junit.jupiter.api.Assertions.assertTrue;
3939

4040
@MojoTest
4141
class TestCollectMojo {
@@ -105,7 +105,7 @@ void testSilent(CollectDependenciesMojo mojo) throws Exception {
105105
assertFalse(mojo.getLog() instanceof DependencySilentLog);
106106

107107
mojo.setSilent(true);
108-
assertTrue(mojo.getLog() instanceof DependencySilentLog);
108+
assertInstanceOf(DependencySilentLog.class, mojo.getLog());
109109

110110
mojo.setSilent(false);
111111
assertFalse(mojo.getLog() instanceof DependencySilentLog);

src/test/java/org/apache/maven/plugins/dependency/pom/PomEditorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,9 @@ void addDependencyIgnoresEmptyStringFields() throws IOException {
752752

753753
String result = new String(Files.readAllBytes(pomFile.toPath()), StandardCharsets.UTF_8);
754754
assertTrue(result.contains("<version>1.0</version>"), "version should be present");
755-
assertTrue(!result.contains("<scope>"), "empty scope should not create element");
756-
assertTrue(!result.contains("<type>"), "empty type should not create element");
757-
assertTrue(!result.contains("<classifier>"), "empty classifier should not create element");
755+
assertFalse(result.contains("<scope>"), "empty scope should not create element");
756+
assertFalse(result.contains("<type>"), "empty type should not create element");
757+
assertFalse(result.contains("<classifier>"), "empty classifier should not create element");
758758
}
759759

760760
@Test
@@ -856,7 +856,7 @@ void removeDependencyFromProfile() throws IOException {
856856

857857
assertTrue(removed, "should find and remove the profile dependency");
858858
String result = new String(Files.readAllBytes(pomFile.toPath()), StandardCharsets.UTF_8);
859-
assertTrue(!result.contains("profile-lib"), "profile dep should be removed");
859+
assertFalse(result.contains("profile-lib"), "profile dep should be removed");
860860
assertTrue(result.contains("top-level"), "top-level dep should remain");
861861
}
862862

src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
3333
import static org.junit.jupiter.api.Assertions.assertEquals;
3434
import static org.junit.jupiter.api.Assertions.assertFalse;
35-
import static org.junit.jupiter.api.Assertions.assertTrue;
35+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
3636
import static org.junit.jupiter.api.AssertionsKt.assertNotNull;
3737

3838
@MojoTest
@@ -77,7 +77,7 @@ void testSilent(ResolveDependenciesMojo mojo) {
7777
assertFalse(mojo.getLog() instanceof DependencySilentLog);
7878

7979
mojo.setSilent(true);
80-
assertTrue(mojo.getLog() instanceof DependencySilentLog);
80+
assertInstanceOf(DependencySilentLog.class, mojo.getLog());
8181

8282
mojo.setSilent(false);
8383
assertFalse(mojo.getLog() instanceof DependencySilentLog);

src/test/java/org/apache/maven/plugins/dependency/utils/translators/TestClassifierTypeTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ void testClassifierAndType() {
141141
org.eclipse.aether.artifact.Artifact translatedArtifact = resultIter.next();
142142
if (artifact.getArtifactId() == translatedArtifact.getArtifactId()
143143
&& artifact.getGroupId() == translatedArtifact.getGroupId()) {
144-
assertEquals(translatedArtifact.getClassifier(), classifier);
145-
assertEquals(translatedArtifact.getExtension(), type);
144+
assertEquals(classifier, translatedArtifact.getClassifier());
145+
assertEquals(type, translatedArtifact.getExtension());
146146

147147
found = true;
148148
break;

0 commit comments

Comments
 (0)