@@ -681,4 +681,80 @@ public void testToList() {
681681 List <String > values = JavadocUtil .toList (value );
682682 assertThat (values ).containsExactly ("*.internal" , "org.acme.exclude1.*" , "org.acme.exclude2" );
683683 }
684+
685+ /**
686+ * Test for getExcludedPackages with wildcard patterns
687+ */
688+ public void testGetExcludedPackages () throws Exception {
689+ // Create test directory structure
690+ File testDir = new File (getBasedir (), "target/test/unit/exclude-packages-test" );
691+ if (testDir .exists ()) {
692+ FileUtils .deleteDirectory (testDir );
693+ }
694+
695+ // Create package structure:
696+ // org.example (with Main.java)
697+ // org.example.sub1 (with Class1.java)
698+ // org.example.sub2 (with Class2.java)
699+ // org.example.sub2.subsub (with Class3.java)
700+ // org.other (with Other.java)
701+ // com.internal (with Internal.java)
702+
703+ File orgExample = new File (testDir , "org/example" );
704+ File orgExampleSub1 = new File (testDir , "org/example/sub1" );
705+ File orgExampleSub2 = new File (testDir , "org/example/sub2" );
706+ File orgExampleSub2Subsub = new File (testDir , "org/example/sub2/subsub" );
707+ File orgOther = new File (testDir , "org/other" );
708+ File comInternal = new File (testDir , "com/internal" );
709+
710+ assertTrue (orgExample .mkdirs ());
711+ assertTrue (orgExampleSub1 .mkdirs ());
712+ assertTrue (orgExampleSub2 .mkdirs ());
713+ assertTrue (orgExampleSub2Subsub .mkdirs ());
714+ assertTrue (orgOther .mkdirs ());
715+ assertTrue (comInternal .mkdirs ());
716+
717+ // Create Java files in each directory
718+ new File (orgExample , "Main.java" ).createNewFile ();
719+ new File (orgExampleSub1 , "Class1.java" ).createNewFile ();
720+ new File (orgExampleSub2 , "Class2.java" ).createNewFile ();
721+ new File (orgExampleSub2Subsub , "Class3.java" ).createNewFile ();
722+ new File (orgOther , "Other.java" ).createNewFile ();
723+ new File (comInternal , "Internal.java" ).createNewFile ();
724+
725+ Path testPath = testDir .toPath ();
726+
727+ // Test 1: org.example.* should match all subpackages of org.example
728+ // Expected: org.example.sub1, org.example.sub2, org.example.sub2.subsub
729+ Collection <String > excludes1 = Collections .singletonList ("org.example.*" );
730+ Collection <String > result1 = JavadocUtil .getExcludedPackages (testPath , excludes1 );
731+ assertThat (result1 )
732+ .as ("org.example.* should match all subpackages of org.example" )
733+ .containsExactlyInAnyOrder ("org.example.sub1" , "org.example.sub2" , "org.example.sub2.subsub" );
734+
735+ // Test 2: org.example should match only org.example itself
736+ Collection <String > excludes2 = Collections .singletonList ("org.example" );
737+ Collection <String > result2 = JavadocUtil .getExcludedPackages (testPath , excludes2 );
738+ assertThat (result2 )
739+ .as ("org.example should match only org.example package" )
740+ .containsExactly ("org.example" );
741+
742+ // Test 3: *.internal should match any package ending with .internal
743+ Collection <String > excludes3 = Collections .singletonList ("*.internal" );
744+ Collection <String > result3 = JavadocUtil .getExcludedPackages (testPath , excludes3 );
745+ assertThat (result3 ).as ("*.internal should match com.internal" ).containsExactly ("com.internal" );
746+
747+ // Test 4: org.*.sub1 should match org.example.sub1 (wildcard in the middle matches exactly one level)
748+ Collection <String > excludes4 = Collections .singletonList ("org.*.sub1" );
749+ Collection <String > result4 = JavadocUtil .getExcludedPackages (testPath , excludes4 );
750+ assertThat (result4 ).as ("org.*.sub1 should match org.example.sub1" ).containsExactly ("org.example.sub1" );
751+
752+ // Test 5: Multiple patterns
753+ Collection <String > excludes5 = Arrays .asList ("org.example.*" , "org.other" );
754+ Collection <String > result5 = JavadocUtil .getExcludedPackages (testPath , excludes5 );
755+ assertThat (result5 )
756+ .as ("Multiple patterns should work together" )
757+ .containsExactlyInAnyOrder (
758+ "org.example.sub1" , "org.example.sub2" , "org.example.sub2.subsub" , "org.other" );
759+ }
684760}
0 commit comments