Skip to content

Commit 9f1e7cf

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

File tree

1 file changed

+69
-46
lines changed

1 file changed

+69
-46
lines changed

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

Lines changed: 69 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,85 +20,108 @@
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 org.assertj.core.api.Assertions.assertThat;
3233
import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
3334
import static org.junit.jupiter.api.Assertions.assertEquals;
3435

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

4073
@Test
41-
@SuppressWarnings("checkstyle:UnusedLocalVariable")
4274
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) {
75+
for (String line : Files.readAllLines(getTestFile(ARTIFACT_HANDLERS_APT).toPath())) {
4876
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-
6277
int i = 0;
63-
for (String col : cols) {
64-
assertEquals(expected[i++], col.trim(), "Wrong column header");
78+
for (String col : line.split("\\|\\|")) {
79+
assertEquals(EXPECTED_COLUMN_HEADERS[i++], col.trim(), "Wrong column header");
6580
}
6681
} else if (line.startsWith("|")) {
6782
String[] cols = line.split("\\|");
68-
6983
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");
84+
assertHeader(
85+
type,
86+
trimApt(cols[3], type),
87+
trimApt(cols[4], type),
88+
trimApt(cols[2]),
89+
trimApt(cols[5]),
90+
trimApt(cols[6]),
91+
trimApt(cols[7]));
9092
}
9193
}
9294
}
9395

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

99123
private String trimApt(String content) {
100-
content = content.replace('<', ' ').replace('>', ' ').trim();
101-
102-
return (content.length() == 0) ? null : content;
124+
String value = content.replace('<', ' ').replace('>', ' ').trim();
125+
return value.isEmpty() ? null : value;
103126
}
104127
}

0 commit comments

Comments
 (0)