Skip to content

Commit

Permalink
Add reproducer for JDK 8 bridge method issue
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Apr 29, 2024
1 parent d1a4d03 commit bd07d9c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
plugins {
java
}

// grab jupiter version from system environment
val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION")
val vintageVersion: String = System.getenv("JUNIT_VINTAGE_VERSION")
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")

repositories {
maven { url = uri(file(System.getProperty("maven.repo"))) }
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion")
testImplementation("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-reporting:$platformVersion")
}

tasks.test {
useJUnitPlatform()

testLogging {
events("failed")
}

reports {
html.required = true
}

val outputDir = reports.junitXml.outputLocation
jvmArgumentProviders += CommandLineArgumentProvider {
listOf(
"-Djunit.platform.reporting.open.xml.enabled=true",
"-Djunit.platform.reporting.output.dir=${outputDir.get().asFile.absolutePath}"
)
}

doFirst {
println("Using Java version: ${JavaVersion.current()}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "reflection-tests"
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package standalone;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;

import java.util.Arrays;
import java.util.stream.Stream;

import org.junit.jupiter.api.DynamicNode;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor;
import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
import org.junit.jupiter.engine.descriptor.JupiterTestDescriptor;
import org.junit.jupiter.engine.descriptor.MethodBasedTestDescriptor;
import org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor;

class ReflectionTestCase {

@TestFactory
Stream<DynamicNode> canReadParameters() {
return Stream.of(JupiterTestDescriptor.class, ClassBasedTestDescriptor.class, ClassTestDescriptor.class,
MethodBasedTestDescriptor.class, TestMethodTestDescriptor.class, TestTemplateTestDescriptor.class,
TestTemplateInvocationTestDescriptor.class, TestFactoryTestDescriptor.class,
NestedClassTestDescriptor.class) //
.map(descriptorClass -> dynamicContainer(descriptorClass.getSimpleName(),
Arrays.stream(descriptorClass.getDeclaredMethods()) //
.map(method -> dynamicTest(method.getName(),
() -> assertDoesNotThrow(method::getParameters)))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package platform.tooling.support.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static platform.tooling.support.Helper.TOOL_TIMEOUT;

import java.nio.file.Paths;

import de.sormuras.bartholdy.tool.GradleWrapper;

import org.junit.jupiter.api.Test;
import org.opentest4j.TestAbortedException;

import platform.tooling.support.Helper;
import platform.tooling.support.MavenRepo;
import platform.tooling.support.Request;

/**
* @since 1.11
*/
class ReflectionCompatibilityTests {

@Test
void gradle_wrapper() {
var request = Request.builder() //
.setTool(new GradleWrapper(Paths.get(".."))) //
.setProject("reflection-tests") //
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("build", "--no-daemon", "--stacktrace") //
.setTimeout(TOOL_TIMEOUT) //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.build();

var result = request.run();

assertFalse(result.isTimedOut(), () -> "tool timed out: " + result);

assertEquals(0, result.getExitCode());
assertTrue(result.getOutputLines("out").stream().anyMatch(line -> line.contains("BUILD SUCCESSFUL")));
assertThat(result.getOutput("out")).contains("Using Java version: 1.8");
}
}

0 comments on commit bd07d9c

Please sign in to comment.