Skip to content

Conversation

@vijaykriishna
Copy link
Contributor

@vijaykriishna vijaykriishna commented Nov 8, 2025

Title: [https://github.com//issues/10389] tests(maven#10389): Adding DefaultDependencyResolverResultTest

Added unit tests for DefaultDependencyResolverResult
Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@vijaykriishna vijaykriishna marked this pull request as ready for review November 8, 2025 00:55
Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

Using DefaultType will remove 150 lines of code and will make the test more readable.

Dependency dep = mock(Dependency.class);
when(dep.getGroupId()).thenReturn("g");
when(dep.getArtifactId()).thenReturn("a");
when(dep.getType()).thenReturn(new org.apache.maven.api.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be easier to use org.apache.maven.impl.resolver.type.DefaultType instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be easier to use org.apache.maven.impl.resolver.type.DefaultType instead.

Done.

Dependency dep = mock(Dependency.class);
when(dep.getGroupId()).thenReturn("g");
when(dep.getArtifactId()).thenReturn("a");
when(dep.getType()).thenReturn(new org.apache.maven.api.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same...

Done.

Path p = Files.createTempFile("unres", ".jar");

// Type returns a known CLASSES and an unknown custom PathType => selectPathType should return empty
when(dep.getType()).thenReturn(new org.apache.maven.api.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same...

Done.

Dependency dep = mock(Dependency.class);
when(dep.getGroupId()).thenReturn("g3");
when(dep.getArtifactId()).thenReturn("a3");
when(dep.getType()).thenReturn(new org.apache.maven.api.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same...

Done.

Dependency dep1 = mock(Dependency.class);
when(dep1.getGroupId()).thenReturn("g1");
when(dep1.getArtifactId()).thenReturn("a1");
when(dep1.getType()).thenReturn(new org.apache.maven.api.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same...

Done.

Dependency dep2 = mock(Dependency.class);
when(dep2.getGroupId()).thenReturn("g2");
when(dep2.getArtifactId()).thenReturn("a2");
when(dep2.getType()).thenReturn(new org.apache.maven.api.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same...

Done.

Dependency mainDep = mock(Dependency.class);
when(mainDep.getGroupId()).thenReturn("gX");
when(mainDep.getArtifactId()).thenReturn("aX");
when(mainDep.getType()).thenReturn(new org.apache.maven.api.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same...

Done.

Dependency patchDep = mock(Dependency.class);
when(patchDep.getGroupId()).thenReturn("gX");
when(patchDep.getArtifactId()).thenReturn("aX"); // same identifiers -> findArtifactPath should find mainDep
when(patchDep.getType()).thenReturn(new org.apache.maven.api.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same...

Done.

@gnodet gnodet added this to the 4.1.0 milestone Nov 18, 2025
@vijaykriishna vijaykriishna force-pushed the tests/MNG-8697-DefaultDependencyResolverResultTest branch from 849ec97 to d0db7d2 Compare November 19, 2025 00:08
@vijaykriishna vijaykriishna requested a review from gnodet November 19, 2025 00:11
@vijaykriishna
Copy link
Contributor Author

Using DefaultType will remove 150 lines of code and will make the test more readable.

Done.

when(dep.getArtifactId()).thenReturn("a");
when(dep.getType())
.thenReturn(new DefaultType(
"jar", org.apache.maven.api.Language.JAVA_FAMILY, "jar", null, false, JavaPathType.MODULES));
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using a method createJarType(JavaPathType.MODULES) that can be reused at the 5 locations. Alternatively, using constants could work too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider using a method createJarType(JavaPathType.MODULES) that can be reused at the 5 locations. Alternatively, using constants could work too.

Came up with a reusable method.

Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

Use a method or constants instead of those long calls to the constructors.

@vijaykriishna vijaykriishna force-pushed the tests/MNG-8697-DefaultDependencyResolverResultTest branch from d76590a to dafad48 Compare November 27, 2025 06:56
@vijaykriishna vijaykriishna requested a review from gnodet November 27, 2025 06:56
@vijaykriishna
Copy link
Contributor Author

Use a method or constants instead of those long calls to the constructors.

Came up with a reusable method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants