2020
2121import javax .inject .Inject ;
2222
23- import java .io .File ;
2423import java .nio .file .Files ;
2524import java .util .List ;
2625
2928import org .codehaus .plexus .testing .PlexusTest ;
3029import org .junit .jupiter .api .Test ;
3130
31+ import static org .assertj .core .api .Assertions .assertThat ;
3232import static org .codehaus .plexus .testing .PlexusExtension .getTestFile ;
3333import static org .junit .jupiter .api .Assertions .assertEquals ;
3434
3535@ PlexusTest
3636class ArtifactHandlerTest {
37+ private static final String [] EXPECTED_COLUMN_HEADERS = new String [] {
38+ "" , "type" , "classifier" , "extension" , "packaging" , "language" , "added to classpath" , "includesDependencies"
39+ };
40+ private static final List <String > VALID_PACKAGING_TYPES = List .of (
41+ "pom" ,
42+ "jar" ,
43+ "test-jar" ,
44+ "maven-plugin" ,
45+ "ejb" ,
46+ "war" ,
47+ "ear" ,
48+ "rar" ,
49+ "java-source" ,
50+ "javadoc" ,
51+ "aar" ,
52+ "apk" ,
53+ "bundle" ,
54+ "eclipse-plugin" ,
55+ "eclipse-test-plugin" ,
56+ "hpi" ,
57+ "jpi" ,
58+ "kar" ,
59+ "lpkg" ,
60+ "maven-archetype" ,
61+ "nar" ,
62+ "par" ,
63+ "sar" ,
64+ "swc" ,
65+ "swf" ,
66+ "zip" );
67+
3768 @ Inject
3869 PlexusContainer container ;
3970
4071 @ Test
41- @ SuppressWarnings ("checkstyle:UnusedLocalVariable" )
4272 void testAptConsistency () throws Exception {
43- File apt = getTestFile ("src/site/apt/artifact-handlers.apt" );
44-
45- List <String > lines = Files .readAllLines (apt .toPath ());
46-
47- for (String line : lines ) {
73+ for (String line : Files .readAllLines (
74+ getTestFile ("src/site/apt/artifact-handlers.apt" ).toPath ())) {
4875 if (line .startsWith ("||" )) {
49- String [] cols = line .split ("\\ |\\ |" );
50- String [] expected = new String [] {
51- "" ,
52- "type" ,
53- "classifier" ,
54- "extension" ,
55- "packaging" ,
56- "language" ,
57- "added to classpath" ,
58- "includesDependencies" ,
59- ""
60- };
61-
6276 int i = 0 ;
63- for (String col : cols ) {
64- assertEquals (expected [i ++], col .trim (), "Wrong column header" );
77+ for (String col : line . split ( " \\ | \\ |" ) ) {
78+ assertEquals (EXPECTED_COLUMN_HEADERS [i ++], col .trim (), "Wrong column header" );
6579 }
6680 } else if (line .startsWith ("|" )) {
6781 String [] cols = line .split ("\\ |" );
@@ -79,6 +93,8 @@ void testAptConsistency() throws Exception {
7993 assertEquals (handler .getExtension (), extension , type + " extension" );
8094 // Packaging/Directory is Maven1 remnant!!!
8195 // assertEquals(handler.getPackaging(), packaging, type + " packaging");
96+ assertThat (handler .getPackaging ()).isNotEmpty ();
97+ assertThat (VALID_PACKAGING_TYPES ).contains (packaging );
8298 assertEquals (handler .getClassifier (), classifier , type + " classifier" );
8399 assertEquals (handler .getLanguage (), language , type + " language" );
84100 assertEquals (
@@ -97,8 +113,7 @@ private String trimApt(String content, String type) {
97113 }
98114
99115 private String trimApt (String content ) {
100- content = content .replace ('<' , ' ' ).replace ('>' , ' ' ).trim ();
101-
102- return (content .length () == 0 ) ? null : content ;
116+ String value = content .replace ('<' , ' ' ).replace ('>' , ' ' ).trim ();
117+ return value .isEmpty () ? null : value ;
103118 }
104119}
0 commit comments