@Test public void testGetOakpalCoreVersionWithApi() { final OpearPackageMojo mojo = newMojo(); final MavenProject project = mock(MavenProject.class); mojo.project = project; final MavenSession session = mock(MavenSession.class); mojo.session = session; final MavenExecutionRequest executionRequest = mock(MavenExecutionRequest.class); when(session.getRequest()).thenReturn(executionRequest); final String expectVersion = "0.31415926535898"; final Dependency oakpalApiDep = new DependencyFilter() .withGroupId(OAKPAL_GROUP_ID) .withArtifactId(OAKPAL_API_ARTIFACT_ID) .withVersion(expectVersion) .toDependency(); when(project.getDependencies()).thenReturn(Collections.singletonList(oakpalApiDep)); final RepositorySystem repositorySystem = mock(RepositorySystem.class); mojo.repositorySystem = repositorySystem; final Artifact oakpalApiArt = mock(Artifact.class); final ArtifactResolutionResult result = mock(ArtifactResolutionResult.class); when(result.getArtifacts()).thenReturn(Collections.singleton(oakpalApiArt)); when(oakpalApiArt.getGroupId()).thenReturn(OAKPAL_GROUP_ID); when(oakpalApiArt.getArtifactId()).thenReturn(OAKPAL_API_ARTIFACT_ID); when(oakpalApiArt.getVersion()).thenReturn(expectVersion); when(repositorySystem.createDependencyArtifact(oakpalApiDep)).thenReturn(oakpalApiArt); doAnswer(call -> { final ArtifactResolutionRequest request = call.getArgument(0, ArtifactResolutionRequest.class); if (request.getArtifact() == oakpalApiArt) { return result; } else { return null; } }).when(repositorySystem).resolve(any(ArtifactResolutionRequest.class)); assertEquals("expect version", expectVersion, mojo.getOakpalCoreVersion()); }
String getOakpalCoreVersion() { return resolveArtifacts(project.getDependencies(), true).stream() .filter(TEST_IS_OAKPAL_CORE.or(TEST_IS_OAKPAL_API)) .findFirst() .map(Artifact::getVersion).orElse(getOwnVersion()); }
OpearPackageMojo extends AbstractCommonMojo { String getOakpalCoreVersion() { return resolveArtifacts(project.getDependencies(), true).stream() .filter(TEST_IS_OAKPAL_CORE.or(TEST_IS_OAKPAL_API)) .findFirst() .map(Artifact::getVersion).orElse(getOwnVersion()); } }
OpearPackageMojo extends AbstractCommonMojo { String getOakpalCoreVersion() { return resolveArtifacts(project.getDependencies(), true).stream() .filter(TEST_IS_OAKPAL_CORE.or(TEST_IS_OAKPAL_API)) .findFirst() .map(Artifact::getVersion).orElse(getOwnVersion()); }  }
OpearPackageMojo extends AbstractCommonMojo { String getOakpalCoreVersion() { return resolveArtifacts(project.getDependencies(), true).stream() .filter(TEST_IS_OAKPAL_CORE.or(TEST_IS_OAKPAL_API)) .findFirst() .map(Artifact::getVersion).orElse(getOwnVersion()); }  @Override void execute(); }
OpearPackageMojo extends AbstractCommonMojo { String getOakpalCoreVersion() { return resolveArtifacts(project.getDependencies(), true).stream() .filter(TEST_IS_OAKPAL_CORE.or(TEST_IS_OAKPAL_API)) .findFirst() .map(Artifact::getVersion).orElse(getOwnVersion()); }  @Override void execute(); static final String OPEAR; }