11package io .codemodder .plugins .maven .operator ;
22
3- import static org .junit . Assert .* ;
3+ import static org .assertj . core . api . Assertions . assertThat ;
44
55import java .io .File ;
66import java .io .IOException ;
1111import java .util .ArrayList ;
1212import java .util .Collection ;
1313import java .util .List ;
14- import java .util .stream .Collectors ;
1514import javax .xml .stream .XMLStreamException ;
1615import org .dom4j .DocumentException ;
1716import org .junit .jupiter .api .Test ;
2120final class POMOperatorDependencyQueryTest {
2221 private static final Logger LOGGER = LoggerFactory .getLogger (POMOperatorTest .class );
2322
23+ /**
24+ * Tests whether queryDependency uses the safe query type and retrieves dependencies successfully.
25+ * Ensures that dependencies are retrieved when a safe query type is used.
26+ */
2427 @ Test
25- void testBasicQuery ()
28+ void queryDependency_uses_safe_query_type_successfully ()
2629 throws DocumentException , IOException , URISyntaxException , XMLStreamException {
2730 ProjectModelFactory context = ProjectModelFactory .load (getClass ().getResource ("pom-1.xml" ));
2831 context .withSafeQueryType ();
@@ -31,61 +34,80 @@ void testBasicQuery()
3134
3235 LOGGER .debug ("Dependencies found: {}" , dependencies );
3336
34- assertTrue ("Dependencies are not empty" , dependencies != null && !dependencies .isEmpty ());
37+ // "Dependencies are not empty"
38+ assertThat (dependencies != null && !dependencies .isEmpty ()).isTrue ();
3539 }
3640
41+ /**
42+ * Tests queryDependency for a broken POM, expecting no dependencies. Verifies that the query for
43+ * a broken POM returns an empty list of dependencies.
44+ */
3745 @ Test
38- void testFailedSafeQuery ()
46+ void queryDependency_for_broken_pom_returns_no_dependencies ()
3947 throws DocumentException , IOException , URISyntaxException , XMLStreamException {
4048 ProjectModelFactory context =
4149 ProjectModelFactory .load (getClass ().getResource ("pom-broken.xml" ));
4250 context .withSafeQueryType ();
4351
4452 Collection <Dependency > dependencies = POMOperator .queryDependency (context .build ());
4553
46- assertTrue ("Dependencies are empty" , dependencies .isEmpty ());
54+ // "Dependencies are empty"
55+ assertThat (dependencies ).isEmpty ();
4756 }
4857
58+ /**
59+ * Tests whether queryDependency uses available dependency query commands successfully. Verifies
60+ * that the query uses available dependency query commands and returns non-empty dependencies.
61+ */
4962 @ Test
50- void testAllQueryTypes ()
51- throws DocumentException , IOException , URISyntaxException , XMLStreamException {
63+ void queryDependency_uses_available_dependency_query_commands_successfully ()
64+ throws DocumentException ,
65+ IOException ,
66+ URISyntaxException ,
67+ XMLStreamException ,
68+ ClassNotFoundException ,
69+ InstantiationException ,
70+ IllegalAccessException {
5271 String [] pomFiles = {"pom-1.xml" , "pom-3.xml" };
5372 for (String pomFile : pomFiles ) {
5473 for (Pair <QueryType , String > chain : CommandChain .AVAILABLE_DEPENDENCY_QUERY_COMMANDS ) {
5574 String commandClassName = "io.codemodder.plugins.maven.operator." + chain .getSecond ();
5675
5776 List <Command > commandListOverride = new ArrayList <>();
58- try {
59- Command command = (Command ) Class .forName (commandClassName ).newInstance ();
60- commandListOverride .add (command );
61- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e ) {
62- e .printStackTrace ();
63- }
77+
78+ Command command = (Command ) Class .forName (commandClassName ).newInstance ();
79+ commandListOverride .add (command );
6480
6581 ProjectModelFactory context = ProjectModelFactory .load (getClass ().getResource (pomFile ));
6682 context .withSafeQueryType ();
6783
6884 Collection <Dependency > dependencies =
6985 POMOperator .queryDependency (context .build (), commandListOverride );
7086
71- assertTrue ("Dependencies are not empty" , !dependencies .isEmpty ());
87+ // "Dependencies are not empty"
88+ assertThat (!dependencies .isEmpty ()).isTrue ();
7289 }
7390 }
7491 }
7592
93+ /**
94+ * Tests whether queryDependency uses a temporary directory successfully. Verifies that the query
95+ * uses a temporary directory and returns non-empty dependencies.
96+ */
7697 @ Test
77- void testTemporaryDirectory ()
98+ void queryDependency_uses_temporary_directory_successfully ()
7899 throws IOException , DocumentException , URISyntaxException , XMLStreamException {
79100
80101 File tempDirectory = new File ("/tmp/mvn-repo-" + System .currentTimeMillis () + ".dir" );
81102
82- assertFalse ("Temp Directory does not exist initially" , tempDirectory .exists ());
83- assertEquals (
84- "There must be no files" ,
85- tempDirectory .list () != null
86- ? (int ) Files .list (tempDirectory .toPath ()).filter (Files ::isDirectory ).count ()
87- : 0 ,
88- 0 );
103+ // "Temp Directory does not exist initially"
104+ assertThat (tempDirectory ).doesNotExist ();
105+ // "There must be no files"
106+ assertThat (
107+ tempDirectory .list () != null
108+ ? (int ) Files .list (tempDirectory .toPath ()).filter (Files ::isDirectory ).count ()
109+ : 0 )
110+ .isZero ();
89111
90112 ProjectModelFactory context = ProjectModelFactory .load (getClass ().getResource ("pom-1.xml" ));
91113 context .withSafeQueryType ();
@@ -95,14 +117,22 @@ void testTemporaryDirectory()
95117
96118 LOGGER .debug ("Dependencies found: " + dependencies );
97119
98- assertTrue ("Dependencies are not empty" , dependencies != null && !dependencies .isEmpty ());
120+ // "Dependencies are not empty"
121+ assertThat (dependencies != null && !dependencies .isEmpty ()).isTrue ();
99122
100- assertTrue ("Temp Directory ends up existing" , tempDirectory .exists ());
101- assertTrue ("Temp Directory is a directory" , tempDirectory .isDirectory ());
123+ // "Temp Directory ends up existing"
124+ assertThat (tempDirectory ).exists ();
125+ // "Temp Directory is a directory"
126+ assertThat (tempDirectory ).isDirectory ();
102127 }
103128
129+ /**
130+ * Tests whether queryDependency uses a temporary directory and offline mode successfully.
131+ * Verifies that the query uses a temporary directory and offline mode, returning non-empty
132+ * dependencies.
133+ */
104134 @ Test
105- void testTemporaryDirectoryAndFullyOffline ()
135+ void queryDependency_uses_temporary_directory_and_offline_mode_successfully ()
106136 throws IOException , DocumentException , URISyntaxException , XMLStreamException {
107137
108138 Path tempDirectory = Files .createTempDirectory ("mvn-repo" );
@@ -115,11 +145,16 @@ void testTemporaryDirectoryAndFullyOffline()
115145
116146 LOGGER .debug ("Dependencies found: " + dependencies );
117147
118- assertTrue ("Dependencies are not empty" , !dependencies .isEmpty ());
148+ // "Dependencies are not empty"
149+ assertThat (!dependencies .isEmpty ()).isTrue ();
119150 }
120151
152+ /**
153+ * Tests whether queryDependency handles a synthetic dependency. Verifies the handling of
154+ * synthetic dependencies in the query.
155+ */
121156 @ Test
122- void testOnSyntheticDependency () throws Exception {
157+ void queryDependency_handles_synthetic_dependency () throws Exception {
123158 Path tempDirectory = Files .createTempDirectory ("mvn-repo" );
124159
125160 Path tempPom = tempDirectory .resolve ("pom.xml" );
@@ -159,19 +194,19 @@ void testOnSyntheticDependency() throws Exception {
159194
160195 LOGGER .debug ("Dependencies found: " + dependencies );
161196
162- assertTrue ("Dependencies are not empty" , !dependencies .isEmpty ());
197+ // "Dependencies are not empty"
198+ assertThat (!dependencies .isEmpty ()).isTrue ();
163199
164- assertTrue (
165- "Random name matches" ,
166- dependencies .stream ()
167- .collect (Collectors .toList ())
168- .get (0 )
169- .getArtifactId ()
170- .equals (randomName ));
200+ // "Random name matches"
201+ assertThat (dependencies .stream ().toList ().get (0 ).getArtifactId ()).isEqualTo (randomName );
171202 }
172203
204+ /**
205+ * Tests queryDependency handles a composite synthetic dependency. Verifies the handling of
206+ * composite synthetic dependencies in the query.
207+ */
173208 @ Test
174- void testOnCompositeSyntheticDependency () throws Exception {
209+ void queryDependency_handles_composite_synthetic_dependency () throws Exception {
175210 Path tempDirectory = Files .createTempDirectory ("mvn-repo" );
176211
177212 Path tempParentPom = tempDirectory .resolve ("pom-parent.xml" );
@@ -247,19 +282,21 @@ void testOnCompositeSyntheticDependency() throws Exception {
247282
248283 LOGGER .debug ("Dependencies found: " + dependencies );
249284
250- assertTrue ("Dependencies are not empty" , !dependencies .isEmpty ());
285+ // "Dependencies are not empty"
286+ assertThat (!dependencies .isEmpty ()).isTrue ();
251287
252- assertTrue (
253- "Random name matches" ,
254- dependencies .stream ()
255- .collect (Collectors .toList ())
256- .get (0 )
257- .getArtifactId ()
258- .equals (randomName ));
288+ // "Random name matches"
289+ assertThat (dependencies .stream ().toList ().get (0 ).getArtifactId ()).isEqualTo (randomName );
259290 }
260291
292+ /**
293+ * Tests queryDependency handles composite incomplete synthetic dependency but with a parser.
294+ * Verifies the handling of composite incomplete synthetic dependencies with a parser in the
295+ * query.
296+ */
261297 @ Test
262- void testOnCompositeSyntheticDependencyIncompleteButWithParser () throws Exception {
298+ void queryDependency_handles_composite_incomplete_synthetic_dependency_but_with_parser ()
299+ throws Exception {
263300 Path tempDirectory = Files .createTempDirectory ("mvn-repo" );
264301 Path tempPom = tempDirectory .resolve ("pom.xml" );
265302 String randomName = "random-artifact-" + System .currentTimeMillis ();
@@ -316,7 +353,8 @@ void testOnCompositeSyntheticDependencyIncompleteButWithParser() throws Exceptio
316353
317354 LOGGER .debug ("Dependencies found: {}" , dependencies );
318355
319- assertTrue ("Dependencies are empty" , !dependencies .isEmpty ());
356+ // "Dependencies are empty"
357+ assertThat (!dependencies .isEmpty ()).isTrue ();
320358
321359 Dependency foundDependency =
322360 dependencies .stream ()
@@ -327,7 +365,8 @@ void testOnCompositeSyntheticDependencyIncompleteButWithParser() throws Exceptio
327365 .findAny ()
328366 .orElse (null );
329367
330- assertTrue ("There's a dependency with managed-version" , foundDependency != null );
368+ // "There's a dependency with managed-version",
369+ assertThat (foundDependency ).isNotNull ();
331370 }
332371
333372 private List <Command > getCommandListFor (String ... names ) {
@@ -348,8 +387,12 @@ private List<Command> getCommandListFor(String... names) {
348387 return commandList ;
349388 }
350389
390+ /**
391+ * Tests queryDependency handles offline mode. Verifies the behavior of dependency retrieval in
392+ * offline mode.
393+ */
351394 @ Test
352- void testOfflineQueryResolution () throws Exception {
395+ void queryDependency_handles_offline_mode () throws Exception {
353396 Path tempDirectory = Files .createTempDirectory ("mvn-repo" );
354397 Path pomFilePath =
355398 Paths .get (getClass ().getResource ("nested/child/pom/pom-3-child.xml" ).toURI ());
@@ -362,6 +405,7 @@ void testOfflineQueryResolution() throws Exception {
362405
363406 LOGGER .debug ("Dependencies found: {}" , dependencies );
364407
365- assertTrue ("Dependencies are empty" , dependencies .isEmpty ());
408+ // "Dependencies are empty"
409+ assertThat (dependencies ).isEmpty ();
366410 }
367411}
0 commit comments