Skip to content

Commit 1fb36a4

Browse files
author
Vincent Potucek
committed
add test assertion to resolve @SuppressWarnings("checkstyle:UnusedLocalVariable")
1 parent 96efade commit 1fb36a4

File tree

1 file changed

+70
-46
lines changed

1 file changed

+70
-46
lines changed

impl/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java

Lines changed: 70 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,85 +20,109 @@
2020

2121
import javax.inject.Inject;
2222

23-
import java.io.File;
2423
import java.nio.file.Files;
2524
import java.util.List;
2625

2726
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
2827
import org.codehaus.plexus.PlexusContainer;
28+
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
2929
import org.codehaus.plexus.testing.PlexusTest;
3030
import org.junit.jupiter.api.Test;
3131

32+
import static java.nio.file.Files.readAllLines;
33+
import static org.assertj.core.api.Assertions.assertThat;
3234
import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
3335
import static org.junit.jupiter.api.Assertions.assertEquals;
3436

3537
@PlexusTest
3638
class ArtifactHandlerTest {
39+
private static final String[] EXPECTED_COLUMN_HEADERS = new String[] {
40+
"", "type", "classifier", "extension", "packaging", "language", "added to classpath", "includesDependencies"
41+
};
42+
private static final List<String> VALID_PACKAGING_TYPES = List.of(
43+
"aar",
44+
"apk",
45+
"bundle",
46+
"ear",
47+
"eclipse-plugin",
48+
"eclipse-test-plugin",
49+
"ejb",
50+
"hpi",
51+
"jar",
52+
"java-source",
53+
"javadoc",
54+
"jpi",
55+
"kar",
56+
"lpkg",
57+
"maven-archetype",
58+
"maven-plugin",
59+
"nar",
60+
"par",
61+
"pom",
62+
"rar",
63+
"sar",
64+
"swc",
65+
"swf",
66+
"test-jar",
67+
"war",
68+
"zip");
69+
private static final String ARTIFACT_HANDLERS_APT = "src/site/apt/artifact-handlers.apt";
70+
3771
@Inject
3872
PlexusContainer container;
3973

4074
@Test
41-
@SuppressWarnings("checkstyle:UnusedLocalVariable")
4275
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) {
76+
for (String line : readAllLines(getTestFile(ARTIFACT_HANDLERS_APT).toPath())) {
4877
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-
6278
int i = 0;
63-
for (String col : cols) {
64-
assertEquals(expected[i++], col.trim(), "Wrong column header");
79+
for (String col : line.split("\\|\\|")) {
80+
assertEquals(EXPECTED_COLUMN_HEADERS[i++], col.trim(), "Wrong column header");
6581
}
6682
} else if (line.startsWith("|")) {
6783
String[] cols = line.split("\\|");
68-
6984
String type = trimApt(cols[1]);
70-
String classifier = trimApt(cols[2]);
71-
String extension = trimApt(cols[3], type);
72-
String packaging = trimApt(cols[4], type);
73-
String language = trimApt(cols[5]);
74-
String addedToClasspath = trimApt(cols[6]);
75-
String includesDependencies = trimApt(cols[7]);
76-
77-
ArtifactHandler handler =
78-
container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type);
79-
assertEquals(handler.getExtension(), extension, type + " extension");
80-
// Packaging/Directory is Maven1 remnant!!!
81-
// assertEquals(handler.getPackaging(), packaging, type + " packaging");
82-
assertEquals(handler.getClassifier(), classifier, type + " classifier");
83-
assertEquals(handler.getLanguage(), language, type + " language");
84-
assertEquals(
85-
handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath");
86-
assertEquals(
87-
handler.isIncludesDependencies() ? "true" : null,
88-
includesDependencies,
89-
type + " includesDependencies");
85+
assertHeader(
86+
type,
87+
trimApt(cols[3], type),
88+
trimApt(cols[4], type),
89+
trimApt(cols[2]),
90+
trimApt(cols[5]),
91+
trimApt(cols[6]),
92+
trimApt(cols[7]));
9093
}
9194
}
9295
}
9396

97+
private void assertHeader(
98+
String type,
99+
String extension,
100+
String packaging,
101+
String classifier,
102+
String language,
103+
String addedToClasspath,
104+
String includesDependencies)
105+
throws ComponentLookupException {
106+
ArtifactHandler handler = container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type);
107+
assertEquals(handler.getExtension(), extension, type + " extension");
108+
// Packaging/Directory is Maven1 remnant!!!
109+
// assertEquals(handler.getPackaging(), packaging, type + " packaging");
110+
assertThat(handler.getPackaging()).isNotEmpty();
111+
assertThat(VALID_PACKAGING_TYPES).contains(packaging);
112+
assertEquals(handler.getClassifier(), classifier, type + " classifier");
113+
assertEquals(handler.getLanguage(), language, type + " language");
114+
assertEquals(handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath");
115+
assertEquals(
116+
handler.isIncludesDependencies() ? "true" : null, includesDependencies, type + " includesDependencies");
117+
}
118+
94119
private String trimApt(String content, String type) {
95120
String value = trimApt(content);
96121
return "= type".equals(value) ? type : value;
97122
}
98123

99124
private String trimApt(String content) {
100-
content = content.replace('<', ' ').replace('>', ' ').trim();
101-
102-
return (content.length() == 0) ? null : content;
125+
String value = content.replace('<', ' ').replace('>', ' ').trim();
126+
return value.isEmpty() ? null : value;
103127
}
104128
}

0 commit comments

Comments
 (0)