-
Notifications
You must be signed in to change notification settings - Fork 2.8k
add test assertion to resolve @SuppressWarnings("checkstyle:UnusedLocalVariable")
#2365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Pankraz76
wants to merge
1
commit into
apache:master
from
Pankraz76:error-prone-pmd-ArtifactHandlerTest
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,85 +20,109 @@ | |
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import java.io.File; | ||
| import java.nio.file.Files; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; | ||
| import org.codehaus.plexus.PlexusContainer; | ||
| import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | ||
| import org.codehaus.plexus.testing.PlexusTest; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static java.nio.file.Files.readAllLines; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.codehaus.plexus.testing.PlexusExtension.getTestFile; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| @PlexusTest | ||
| class ArtifactHandlerTest { | ||
| private static final String[] EXPECTED_COLUMN_HEADERS = new String[] { | ||
| "", "type", "classifier", "extension", "packaging", "language", "added to classpath", "includesDependencies" | ||
| }; | ||
| private static final List<String> VALID_PACKAGING_TYPES = List.of( | ||
| "aar", | ||
| "apk", | ||
| "bundle", | ||
| "ear", | ||
| "eclipse-plugin", | ||
| "eclipse-test-plugin", | ||
| "ejb", | ||
| "hpi", | ||
| "jar", | ||
| "java-source", | ||
| "javadoc", | ||
| "jpi", | ||
| "kar", | ||
| "lpkg", | ||
| "maven-archetype", | ||
| "maven-plugin", | ||
| "nar", | ||
| "par", | ||
| "pom", | ||
| "rar", | ||
| "sar", | ||
| "swc", | ||
| "swf", | ||
| "test-jar", | ||
| "war", | ||
| "zip"); | ||
| private static final String ARTIFACT_HANDLERS_APT = "src/site/apt/artifact-handlers.apt"; | ||
|
|
||
| @Inject | ||
| PlexusContainer container; | ||
|
|
||
| @Test | ||
| @SuppressWarnings("checkstyle:UnusedLocalVariable") | ||
| void testAptConsistency() throws Exception { | ||
| File apt = getTestFile("src/site/apt/artifact-handlers.apt"); | ||
|
|
||
| List<String> lines = Files.readAllLines(apt.toPath()); | ||
|
|
||
| for (String line : lines) { | ||
| for (String line : readAllLines(getTestFile(ARTIFACT_HANDLERS_APT).toPath())) { | ||
| if (line.startsWith("||")) { | ||
| String[] cols = line.split("\\|\\|"); | ||
| String[] expected = new String[] { | ||
| "", | ||
| "type", | ||
| "classifier", | ||
| "extension", | ||
| "packaging", | ||
| "language", | ||
| "added to classpath", | ||
| "includesDependencies", | ||
| "" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not required. |
||
| }; | ||
|
|
||
| int i = 0; | ||
| for (String col : cols) { | ||
| assertEquals(expected[i++], col.trim(), "Wrong column header"); | ||
| for (String col : line.split("\\|\\|")) { | ||
| assertEquals(EXPECTED_COLUMN_HEADERS[i++], col.trim(), "Wrong column header"); | ||
| } | ||
| } else if (line.startsWith("|")) { | ||
| String[] cols = line.split("\\|"); | ||
|
|
||
| String type = trimApt(cols[1]); | ||
| String classifier = trimApt(cols[2]); | ||
| String extension = trimApt(cols[3], type); | ||
| String packaging = trimApt(cols[4], type); | ||
| String language = trimApt(cols[5]); | ||
| String addedToClasspath = trimApt(cols[6]); | ||
| String includesDependencies = trimApt(cols[7]); | ||
|
|
||
| ArtifactHandler handler = | ||
| container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type); | ||
| assertEquals(handler.getExtension(), extension, type + " extension"); | ||
| // Packaging/Directory is Maven1 remnant!!! | ||
| // assertEquals(handler.getPackaging(), packaging, type + " packaging"); | ||
| assertEquals(handler.getClassifier(), classifier, type + " classifier"); | ||
| assertEquals(handler.getLanguage(), language, type + " language"); | ||
| assertEquals( | ||
| handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath"); | ||
| assertEquals( | ||
| handler.isIncludesDependencies() ? "true" : null, | ||
| includesDependencies, | ||
| type + " includesDependencies"); | ||
| assertHeader( | ||
| type, | ||
| trimApt(cols[3], type), | ||
| trimApt(cols[4], type), | ||
| trimApt(cols[2]), | ||
| trimApt(cols[5]), | ||
| trimApt(cols[6]), | ||
| trimApt(cols[7])); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void assertHeader( | ||
| String type, | ||
| String extension, | ||
| String packaging, | ||
| String classifier, | ||
| String language, | ||
| String addedToClasspath, | ||
| String includesDependencies) | ||
| throws ComponentLookupException { | ||
| ArtifactHandler handler = container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type); | ||
| assertEquals(handler.getExtension(), extension, type + " extension"); | ||
| // Packaging/Directory is Maven1 remnant!!! | ||
| // assertEquals(handler.getPackaging(), packaging, type + " packaging"); | ||
| assertThat(handler.getPackaging()).isNotEmpty(); | ||
| assertThat(VALID_PACKAGING_TYPES).contains(packaging); | ||
| assertEquals(handler.getClassifier(), classifier, type + " classifier"); | ||
| assertEquals(handler.getLanguage(), language, type + " language"); | ||
| assertEquals(handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath"); | ||
| assertEquals( | ||
| handler.isIncludesDependencies() ? "true" : null, includesDependencies, type + " includesDependencies"); | ||
| } | ||
|
|
||
| private String trimApt(String content, String type) { | ||
| String value = trimApt(content); | ||
| return "= type".equals(value) ? type : value; | ||
| } | ||
|
|
||
| private String trimApt(String content) { | ||
| content = content.replace('<', ' ').replace('>', ' ').trim(); | ||
|
|
||
| return (content.length() == 0) ? null : content; | ||
| String value = content.replace('<', ' ').replace('>', ' ').trim(); | ||
| return value.isEmpty() ? null : value; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is required