Skip to content

Commit

Permalink
Adapt VintageMavenIntegrationTests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Nov 28, 2024
1 parent 5d0b83f commit a0beecb
Showing 1 changed file with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,63 @@
package platform.tooling.support.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static platform.tooling.support.Helper.TOOL_TIMEOUT;
import static platform.tooling.support.tests.Projects.copyToWorkspace;

import de.sormuras.bartholdy.Result;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.opentest4j.TestAbortedException;

import platform.tooling.support.Helper;
import platform.tooling.support.MavenRepo;
import platform.tooling.support.Request;
import platform.tooling.support.process.ProcessResult;
import platform.tooling.support.process.ProcessStarters;

class VintageMavenIntegrationTests {

@GlobalResource
LocalMavenRepo localMavenRepo;

@TempDir
Path workspace;

@Test
void unsupportedVersion() {
void unsupportedVersion() throws Exception {
var result = run("4.11");

assertThat(result.getExitCode()).isEqualTo(1);
assertThat(result.getOutput("out")) //
assertThat(result.exitCode()).isEqualTo(1);
assertThat(result.stdOut()) //
.contains("TestEngine with ID 'junit-vintage' failed to discover tests") //
.contains("Tests run: 0, Failures: 0, Errors: 0, Skipped: 0");
}

@ParameterizedTest(name = "{0}")
@ValueSource(strings = { "4.12", "4.13.2" })
void supportedVersions(String version) {
void supportedVersions(String version) throws Exception {
var result = run(version);

assertThat(result.getExitCode()).isGreaterThan(0);
assertThat(result.getOutput("out")) //
assertThat(result.exitCode()).isGreaterThan(0);
assertThat(result.stdOut()) //
.contains("Running com.example.vintage.VintageTest") //
.contains("VintageTest.failure:") //
.contains("Tests run: 2, Failures: 1, Errors: 0, Skipped: 0");

var surefireReportsDir = Request.WORKSPACE.resolve("vintage-maven-" + version).resolve(
"target/surefire-reports");
var surefireReportsDir = workspace.resolve("target/surefire-reports");
assertThat(surefireReportsDir.resolve("com.example.vintage.VintageTest.txt")).isRegularFile();
assertThat(surefireReportsDir.resolve("TEST-com.example.vintage.VintageTest.xml")).isRegularFile();
}

private Result run(String version) {
var result = Request.builder() //
.setTool(Request.maven()) //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.setProject(Projects.VINTAGE) //
.setWorkspace("vintage-maven-" + version) //
private ProcessResult run(String version) throws Exception {
return ProcessStarters.maven() //
.workingDir(copyToWorkspace(Projects.VINTAGE, workspace)) //
.putEnvironment("JAVA_HOME", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.addArguments("clean", "test", "--update-snapshots", "--batch-mode") //
.addArguments(localMavenRepo.toCliArgument(), "-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("-Djunit4Version=" + version) //
.setTimeout(TOOL_TIMEOUT) //
.build() //
.run();
assertFalse(result.isTimedOut(), () -> "tool timed out: " + result);
return result;
.startAndWait();
}

}

0 comments on commit a0beecb

Please sign in to comment.