@@ -1378,6 +1378,102 @@ public void reportFileGenerated(@TempDir Path tempDir) throws Exception {
13781378 assertTrue (content .contains ("default-group:default2-dependency" ) && content .contains ("3.00" ));
13791379 }
13801380
1381+ @ Test
1382+ public void reportFileWithUnknownAndThresholds (@ TempDir Path tempDir ) throws Exception {
1383+ Path reportFile = tempDir .resolve ("libyear_testreport_complex.csv" );
1384+
1385+ LibYearMojo mojo =
1386+ new LibYearMojo (
1387+ mockAetherRepositorySystem (new HashMap <>() {
1388+ {
1389+ put ("up-to-date" , new String [] {"1.0.0" });
1390+ put ("below-threshold" , new String [] {"1.0.0" });
1391+ put ("above-threshold" , new String [] {"1.0.0" });
1392+ put ("unknown-release" , new String [] {"1.0.0" });
1393+ }
1394+ }),
1395+ new ArtifactFactory (mockArtifactHandlerManager ())) {
1396+ {
1397+ Dependency dep1 = DependencyBuilder .newBuilder ()
1398+ .withGroupId ("default-group" )
1399+ .withArtifactId ("up-to-date" )
1400+ .withVersion ("1.0.0" )
1401+ .build ();
1402+
1403+ Dependency dep2 = DependencyBuilder .newBuilder ()
1404+ .withGroupId ("default-group" )
1405+ .withArtifactId ("below-threshold" )
1406+ .withVersion ("1.0.0" )
1407+ .build ();
1408+
1409+ Dependency dep3 = DependencyBuilder .newBuilder ()
1410+ .withGroupId ("default-group" )
1411+ .withArtifactId ("above-threshold" )
1412+ .withVersion ("1.0.0" )
1413+ .build ();
1414+
1415+ Dependency dep4 = DependencyBuilder .newBuilder ()
1416+ .withGroupId ("default-group" )
1417+ .withArtifactId ("unknown-release" )
1418+ .withVersion ("1.0.0" )
1419+ .build ();
1420+
1421+ MavenProject project = new MavenProjectBuilder ()
1422+ .withDependencies (Arrays .asList (dep1 , dep2 , dep3 , dep4 ))
1423+ .build ();
1424+ project .getModel ()
1425+ .getBuild ()
1426+ .setDirectory (tempDir .toAbsolutePath ().toString ());
1427+
1428+ setProject (project );
1429+ allowProcessingAllDependencies (this );
1430+
1431+ setVariableValueToObject (this , "reportFile" , "libyear_testreport_complex.csv" );
1432+ setVariableValueToObject (this , "minLibYearsForReport" , 1.0f );
1433+
1434+ setSession (mockMavenSession (project ));
1435+ setSearchUri ("http://localhost:8090" );
1436+
1437+ setLog (new InMemoryTestLogger ());
1438+ }
1439+ };
1440+
1441+ LocalDateTime now = LocalDateTime .now ();
1442+
1443+ // dep1: up-to-date (0 years)
1444+ stubResponseFor ("default-group" , "up-to-date" , "1.0.0" , now );
1445+
1446+ // dep2: below-threshold (0.5 years)
1447+ stubResponseFor ("default-group" , "below-threshold" , "1.0.0" , now .minusMonths (6 ));
1448+
1449+ // dep3: above-threshold (2 years)
1450+ stubResponseFor ("default-group" , "above-threshold" , "1.0.0" , now .minusYears (2 ));
1451+
1452+ // dep4: unknown-release (API returns empty or error)
1453+ stubFor (get (urlPathEqualTo ("/solrsearch/select" ))
1454+ .withQueryParam ("q" , equalTo ("g:default-group AND a:unknown-release AND v:1.0.0" ))
1455+ .withQueryParam ("wt" , equalTo ("json" ))
1456+ .willReturn (ok ("{\" response\" :{\" docs\" :[],\" numFound\" :0}}" )));
1457+
1458+ mojo .execute ();
1459+
1460+ String content = Files .readString (reportFile );
1461+
1462+ // dep1 (up-to-date) should NOT be in the report because libYearsOutdated is 0
1463+ assertFalse (content .contains ("default-group:up-to-date" ), "Up-to-date dependency should be omitted" );
1464+
1465+ // dep2 (below-threshold) should NOT be in the report because 0.5 < 1.0
1466+ assertFalse (content .contains ("default-group:below-threshold" ), "Dependency below threshold should be omitted" );
1467+
1468+ // dep3 (above-threshold) SHOULD be in the report
1469+ assertTrue (content .contains ("default-group:above-threshold" ), "Dependency above threshold should be included" );
1470+ assertTrue (content .contains ("2.00" ), "Dependency above threshold should have correct age" );
1471+
1472+ // dep4 (unknown) SHOULD be in the report as "unknown"
1473+ assertTrue (content .contains ("default-group:unknown-release" ), "Unknown release dependency should be included" );
1474+ assertTrue (content .contains ("unknown" ), "Unknown release dependency should be marked as unknown" );
1475+ }
1476+
13811477 private void allowProcessingAllDependencies (LibYearMojo mojo ) throws IllegalAccessException {
13821478 setVariableValueToObject (mojo , "ignoredVersions" , emptySet ());
13831479 setVariableValueToObject (mojo , "processDependencies" , true );
0 commit comments