Skip to content

Assert the source archive itself is absent in testNoSources - #318

Merged
elharo merged 1 commit into
apache:masterfrom
kratos0718:fix/308-assert-jar-absence
Aug 5, 2026
Merged

elharo merged 1 commit into
apache:masterfrom
kratos0718:fix/308-assert-jar-absence

Conversation

@kratos0718

Copy link
Copy Markdown
Contributor

Fixes #308

Problem

Both testNoSources cases assert that no archive was produced like this:

final File expectedFile = getTestTargetDir("project-005");
assertFalse(
        expectedFile.exists(),
        "Source archive should not have been created[" + expectedFile.getAbsolutePath() + "]");

getTestTargetDir returns the project's target directory, not the artifact. So the assertion never inspects the jar named in its own failure message — it is bound to whether a directory happens to exist rather than to whether the mojo produced an archive. A directory left behind by earlier build scaffolding, or created for unrelated reasons, is enough to change the outcome, and conversely the check cannot notice a stray jar inside a directory that does exist.

Fix

Assert the specific artifact instead, reusing the helpers already on AbstractSourcePluginTestCase:

  • SourceJarMojoTest → getSourceArchive(getTestTargetDir("project-005"), "project-005")
  • TestSourceJarMojoTest → getTestSourceArchive(getTestTargetDir("project-005"), "project-005")

These are the same helpers the positive cases use via assertSourceArchive / assertTestSourceArchive, so each negative test now checks exactly the path its positive counterpart asserts, and the failure message names the file that was actually examined.

Testing

mvn test — 10 tests across both classes, all passing. Two lines changed, no production code touched.

Both testNoSources cases asserted that getTestTargetDir("project-005")
does not exist. That helper returns the project's target directory, not
the artifact, so the assertion does not actually check what its message
claims - and it is tied to whether a directory happens to be present
rather than to whether the mojo produced an archive.

Assert the specific jar instead, reusing the existing getSourceArchive
and getTestSourceArchive helpers so each test checks the same artifact
path its positive counterpart asserts.

Fixes apache#308
@elharo
elharo merged commit 65cc352 into apache:master Aug 5, 2026
8 checks passed
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

@elharo Please assign appropriate label to PR according to the type of change.

@github-actions github-actions Bot added this to the 4.0.0 milestone Aug 5, 2026
@elharo elharo added the bug Something isn't working label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testNoSources checks directory existence instead of jar file absence

2 participants