Skip to content

Commit

Permalink
Add Test-Case for transitive resolution of dependency
Browse files Browse the repository at this point in the history
Reproducer for eclipse-m2e#1501
  • Loading branch information
HannesWell committed Aug 22, 2023
1 parent 3410597 commit 3382aa7
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>foo.bar</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>project.a</artifactId>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>foo.bar</groupId>
<artifactId>project.b</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<!-- Depends on junit-jupiter-api 5.7 and must be listed first-->
<groupId>foo.bar</groupId>
<artifactId>project.a</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package project.b;

import org.junit.jupiter.api.Assertions;

public class AClass {

public void aMethod() {
// Added in junit-juptier-api 5.8
Assertions.assertInstanceOf(String.class, "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2023-2023 Hannes Wellmann and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Hannes Wellmann - initial API and implementation
*******************************************************************************/
package org.eclipse.m2e.jdt.tests;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
import org.junit.Test;

public class TransitiveDependencyResolutionTest extends AbstractMavenProjectTestCase {

@Test
public void resolutionOfOlderDependencyVersionsAsTransitiveDependency() throws Exception {
IProject projectA = importProject("projects/transitiveDependencyResolution/project.a/pom.xml");
IProject projectB = importProject("projects/transitiveDependencyResolution/project.b/pom.xml");
// Project-A depends on junit-jupiter-api:5.7
// Project-B depends on junit-jupiter-api:5.8 and Project-A
// B also contains a class that references a method added to the Assertions
// class in junit-jupiter-api 5.8.
// The Assertions class itself already existed in 5.7

projectA.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
projectB.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
waitForJobsToComplete();
assertEquals("Project-A has errors", List.of(), findErrorMarkers(projectA));
assertEquals("Project-B has errors", List.of(), findErrorMarkers(projectB));
}

}

0 comments on commit 3382aa7

Please sign in to comment.