Skip to content

Commit 58bbee6

Browse files
authored
Clean up integration tests by removing redundant JRE annotations and comments (#11353)
This commit modernizes several integration tests by simplifying test logic and removing unnecessary checks. Changes include: - MavenITgh10312TerminallyDeprecatedMethodInGuiceTest: Simplified test logic and updated JRE annotations - MavenITmng4747JavaAgentUsedByPluginTest: Removed redundant JRE check comments - MavenITmng7045DropUselessAndOutdatedCdiApiTest: Removed redundant JRE check and comments - MavenITmng7470ResolverTransportTest: Simplified test method structure, inlined redundant methods, removed unused constants - AbstractMavenIntegrationTestCase: Remove utility method for JRE version checking
1 parent 00a108e commit 58bbee6

File tree

5 files changed

+7
-98
lines changed

5 files changed

+7
-98
lines changed

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.io.File;
2222

2323
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.condition.EnabledForJreRange;
25+
import org.junit.jupiter.api.condition.JRE;
2426

2527
import static org.junit.jupiter.api.Assertions.assertFalse;
2628
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -33,8 +35,8 @@ class MavenITgh10312TerminallyDeprecatedMethodInGuiceTest extends AbstractMavenI
3335
MavenITgh10312TerminallyDeprecatedMethodInGuiceTest() {}
3436

3537
@Test
38+
@EnabledForJreRange(min = JRE.JAVA_24)
3639
void worryingShouldNotBePrinted() throws Exception {
37-
requiresJavaVersion("[24,)");
3840
File testDir = extractResources("/gh-10312-terminally-deprecated-method-in-guice");
3941

4042
Verifier verifier = new Verifier(testDir.getAbsolutePath());
@@ -52,8 +54,8 @@ void worryingShouldNotBePrinted() throws Exception {
5254
}
5355

5456
@Test
57+
@EnabledForJreRange(min = JRE.JAVA_24, max = JRE.JAVA_25)
5558
void allowOverwriteByUser() throws Exception {
56-
requiresJavaVersion("[24,26)");
5759
File testDir = extractResources("/gh-10312-terminally-deprecated-method-in-guice");
5860

5961
Verifier verifier = new Verifier(testDir.getAbsolutePath());

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4747JavaAgentUsedByPluginTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public class MavenITmng4747JavaAgentUsedByPluginTest extends AbstractMavenIntegr
4141
*/
4242
@Test
4343
public void testit() throws Exception {
44-
requiresJavaVersion("[1.5,)");
45-
4644
File testDir = extractResources("/mng-4747");
4745

4846
Verifier verifier = newVerifier(testDir.getAbsolutePath());

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7045DropUselessAndOutdatedCdiApiTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public class MavenITmng7045DropUselessAndOutdatedCdiApiTest extends AbstractMave
2727

2828
@Test
2929
public void testShouldNotLeakCdiApi() throws IOException, VerificationException {
30-
// in test Groovy 4.x is used which requires JDK 1.8, so simply skip it for older JDKs
31-
requiresJavaVersion("[1.8,)");
32-
3330
File testDir = extractResources("/mng-7045");
3431
Verifier verifier = newVerifier(testDir.getAbsolutePath());
3532

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7470ResolverTransportTest.java

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
import java.util.HashMap;
2323
import java.util.Map;
2424

25-
import org.apache.maven.artifact.versioning.ArtifactVersion;
26-
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
2725
import org.junit.jupiter.api.AfterEach;
28-
import org.junit.jupiter.api.Assumptions;
2926
import org.junit.jupiter.api.BeforeEach;
3027
import org.junit.jupiter.api.Test;
3128

@@ -40,11 +37,6 @@ public class MavenITmng7470ResolverTransportTest extends AbstractMavenIntegratio
4037

4138
private int port;
4239

43-
private static final ArtifactVersion JDK_TRANSPORT_USABLE_ON_JDK_SINCE = new DefaultArtifactVersion("11");
44-
45-
private static final ArtifactVersion JDK_TRANSPORT_IN_MAVEN_SINCE =
46-
new DefaultArtifactVersion("4.0.0-alpha-9-SNAPSHOT");
47-
4840
@BeforeEach
4941
protected void setUp() throws Exception {
5042
File testDir = extractResources("/mng-7470-resolver-transport");
@@ -100,37 +92,13 @@ private void performTest(/* nullable */ final String transport, final String log
10092

10193
private static final String WAGON_LOG_SNIPPET = "[DEBUG] Using transporter WagonTransporter";
10294

103-
private static final String APACHE_LOG_SNIPPET_OLD = "[DEBUG] Using transporter HttpTransporter";
104-
10595
private static final String APACHE_LOG_SNIPPET = "[DEBUG] Using transporter ApacheTransporter";
10696

10797
private static final String JDK_LOG_SNIPPET = "[DEBUG] Using transporter JdkTransporter";
10898

109-
/**
110-
* Returns {@code true} if JDK HttpClient transport is usable (Java11 or better).
111-
*/
112-
private boolean isJdkTransportUsable() {
113-
return JDK_TRANSPORT_USABLE_ON_JDK_SINCE.compareTo(getJavaVersion()) < 1;
114-
}
115-
116-
/**
117-
* Returns {@code true} if JDK HttpClient transport is present in Maven (since 4.0.0-alpha-9, the Resolver 2.0.0
118-
* upgrade).
119-
*/
120-
private boolean isJdkTransportPresent() {
121-
return true;
122-
}
123-
124-
private String defaultLogSnippet() {
125-
if (isJdkTransportUsable() && isJdkTransportPresent()) {
126-
return JDK_LOG_SNIPPET;
127-
}
128-
return isJdkTransportPresent() ? APACHE_LOG_SNIPPET : APACHE_LOG_SNIPPET_OLD;
129-
}
130-
13199
@Test
132100
public void testResolverTransportDefault() throws Exception {
133-
performTest(null, defaultLogSnippet());
101+
performTest(null, JDK_LOG_SNIPPET);
134102
}
135103

136104
@Test
@@ -140,14 +108,11 @@ public void testResolverTransportWagon() throws Exception {
140108

141109
@Test
142110
public void testResolverTransportApache() throws Exception {
143-
performTest(
144-
isJdkTransportPresent() ? "apache" : "native",
145-
isJdkTransportPresent() ? APACHE_LOG_SNIPPET : APACHE_LOG_SNIPPET_OLD);
111+
performTest("apache", APACHE_LOG_SNIPPET);
146112
}
147113

148114
@Test
149115
public void testResolverTransportJdk() throws Exception {
150-
Assumptions.assumeTrue(isJdkTransportUsable() && isJdkTransportPresent());
151116
performTest("jdk", JDK_LOG_SNIPPET);
152117
}
153118
}

its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,9 @@
2424
import java.io.InputStream;
2525
import java.io.PrintStream;
2626
import java.util.Arrays;
27-
import java.util.regex.Matcher;
28-
import java.util.regex.Pattern;
29-
30-
import org.apache.maven.artifact.versioning.ArtifactVersion;
31-
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
32-
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
33-
import org.apache.maven.artifact.versioning.VersionRange;
3427
import org.junit.jupiter.api.BeforeAll;
3528
import org.junit.jupiter.api.BeforeEach;
3629
import org.junit.jupiter.api.TestInfo;
37-
import org.opentest4j.TestAbortedException;
3830

3931
/**
4032
* @author Jason van Zyl
@@ -46,8 +38,6 @@ public abstract class AbstractMavenIntegrationTestCase {
4638
*/
4739
private static PrintStream out = System.out;
4840

49-
private static ArtifactVersion javaVersion;
50-
5141
private String testName;
5242

5343
protected AbstractMavenIntegrationTestCase() {}
@@ -68,46 +58,7 @@ protected String getName() {
6858
return testName;
6959
}
7060

71-
/**
72-
* Gets the Java version used to run this test.
73-
*
74-
* @return The Java version, never <code>null</code>.
75-
*/
76-
protected static ArtifactVersion getJavaVersion() {
77-
if (javaVersion == null) {
78-
String version = System.getProperty("java.version");
79-
version = version.replaceAll("[_-]", ".");
80-
Matcher matcher =
81-
Pattern.compile("(?s).*?(([0-9]+\\.[0-9]+)(\\.[0-9]+)?).*").matcher(version);
82-
if (matcher.matches()) {
83-
version = matcher.group(1);
84-
}
85-
javaVersion = new DefaultArtifactVersion(version);
86-
}
87-
return javaVersion;
88-
}
89-
90-
/**
91-
* Guards the execution of a test case by checking that the current Java version matches the specified version
92-
* range. If the check fails, an exception will be thrown which aborts the current test and marks it as skipped. One
93-
* would usually call this method right at the start of a test method.
94-
*
95-
* @param versionRange The version range that specifies the acceptable Java versions for the test, must not be
96-
* <code>null</code>.
97-
*/
98-
protected void requiresJavaVersion(String versionRange) {
99-
VersionRange range;
100-
try {
101-
range = VersionRange.createFromVersionSpec(versionRange);
102-
} catch (InvalidVersionSpecificationException e) {
103-
throw new IllegalArgumentException("Invalid version range: " + versionRange, e);
104-
}
10561

106-
ArtifactVersion version = getJavaVersion();
107-
if (!range.containsVersion(version)) {
108-
throw new UnsupportedJavaVersionException(version, range);
109-
}
110-
}
11162

11263
private static class NonCloseableInputStream extends FilterInputStream {
11364
NonCloseableInputStream(InputStream delegate) {
@@ -118,11 +69,7 @@ private static class NonCloseableInputStream extends FilterInputStream {
11869
public void close() throws IOException {}
11970
}
12071

121-
private static class UnsupportedJavaVersionException extends TestAbortedException {
122-
private UnsupportedJavaVersionException(ArtifactVersion javaVersion, VersionRange supportedRange) {
123-
super("Java version " + javaVersion + " not in range " + supportedRange);
124-
}
125-
}
72+
12673

12774
protected File extractResources(String resourcePath) throws IOException {
12875
return new File(

0 commit comments

Comments
 (0)