Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");
Copy link
Contributor Author

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.

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);
Copy link
Contributor Author

@Pankraz76 Pankraz76 May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both look like bug to me. maven-archetype",
"maven-plugin", "java-source" are all equal so why not these two ? So its not a hyphen thing in general, right?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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(
Expand Down