-
Notifications
You must be signed in to change notification settings - Fork 2.8k
chore: ArtifactHandlerTest improve tests on packaging
#2375
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,16 +29,46 @@ | |
| import org.codehaus.plexus.testing.PlexusTest; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| 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 List<String> PACKAGING_TYPES = List.of( | ||
| "aar", | ||
| "apk", | ||
| "bundle", | ||
| "ear", | ||
| "eclipse-plugin", | ||
| "eclipse-test-plugin", | ||
| "ejb", | ||
| "ejb-client", | ||
| "hpi", | ||
| "jar", | ||
| "java-source", | ||
| "javadoc", | ||
| "jpi", | ||
| "kar", | ||
| "lpkg", | ||
| "maven-archetype", | ||
| "maven-plugin", | ||
| "nar", | ||
| "par", | ||
| "pom", | ||
| "rar", | ||
| "sar", | ||
| "swc", | ||
| "swf", | ||
| "test-jar", | ||
| "war", | ||
| "zip"); | ||
|
|
||
| @Inject | ||
| PlexusContainer container; | ||
|
|
||
| @Test | ||
| @SuppressWarnings("checkstyle:UnusedLocalVariable") | ||
| void testAptConsistency() throws Exception { | ||
| File apt = getTestFile("src/site/apt/artifact-handlers.apt"); | ||
|
|
||
|
|
@@ -77,8 +107,16 @@ void testAptConsistency() throws Exception { | |
| 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(PACKAGING_TYPES).contains(handler.getPackaging(), packaging); | ||
| if (handler.getPackaging().equals("test-jar")) { | ||
| assertEquals("jar", packaging); | ||
| } else if (handler.getPackaging().equals("ejb-client")) { | ||
| assertEquals("ejb", packaging); | ||
|
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. both look like bug to me. maven-archetype",
Contributor
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. I might be starting to see what's going on here. I think you're hitting a weird issue (though WAI) about file extension vs dependency type. See https://maven.apache.org/ref/3.9.9/maven-core/artifact-handlers.html and pages I can't put my finger on right now, but updated a few months ago. That being said, I am more convinced now that this approach is incorrect. We want one single assertEquals that tests a specific value, not contains something from a collection and not "if this assert that". This might mean splitting into multiple test methods. DRY does not apply to tests and asserts. Unit tests should be very straight-forward with no branching and no conditionals.
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. agree.
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. |
||
| } else { | ||
| // Packaging/Directory is Maven1 remnant!!! | ||
| // TODO test with this assertion only | ||
| assertEquals(handler.getPackaging(), packaging, type + " packaging"); | ||
| } | ||
| assertEquals(handler.getClassifier(), classifier, type + " classifier"); | ||
| assertEquals(handler.getLanguage(), language, type + " language"); | ||
| assertEquals( | ||
|
|
||
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.
better some special workaround assert than no at all!
Agree upon test code allowed some flexibility like having commented out code. So lets use this liberty to improve the test by testing the production code.
This topic remains, but we have cleared up the doing and increased coverage.
If/as no ability to fix it yet, might consider take the increment and go for next increment.