Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Use JDK 8
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
sormuras committed Aug 28, 2018
1 parent a47d5fa commit 2a27b83
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cache:
matrix:
fast_finish: true
include:
- jdk: openjdk11
- jdk: oraclejdk8

before_install:
- unset _JAVA_OPTIONS
Expand Down
35 changes: 11 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>10</maven.compiler.release>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.platform.version>1.3.0-RC1</junit.platform.version>
<junit.jupiter.version>5.3.0-RC1</junit.jupiter.version>
<testng.version>6.14.3</testng.version>
Expand All @@ -40,7 +39,7 @@
<!-- Test-only dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<artifactId>junit-jupiter-engine</artifactId> <!-- Surefire needs 'engine', not only 'api' -->
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -96,30 +95,18 @@
</execution>
</executions>
</plugin>
<!-- Use JUnit Platform Plugin -->
<plugin>
<groupId>de.sormuras</groupId>
<artifactId>junit-platform-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<goals>
<goal>launch-junit-platform</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Disable Surefire by binding its 'default-test' goal to phase 'none' -->
<!-- Force Surefire to use the JUnit Platform Provider -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down
38 changes: 15 additions & 23 deletions src/it/basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>10</maven.compiler.release>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand All @@ -21,34 +20,27 @@
<version>@project.version@</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.0-RC1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Use JUnit Platform Plugin -->
<plugin>
<groupId>de.sormuras</groupId>
<artifactId>junit-platform-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<goals>
<goal>launch-junit-platform</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Disable Surefire by binding its 'default-test' goal to phase 'none' -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down
7 changes: 7 additions & 0 deletions src/it/basic/src/test/java/JupiterTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.junit.jupiter.api.Test;

class JupiterTests {

@Test
void jupiter() {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.testng.annotations.Test;

public class BasicTests {
public class TestNGTests {

@Test
public void test1() {}
Expand Down
28 changes: 9 additions & 19 deletions src/it/basic/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,22 @@ String[] files = new String[] {
// compile: main
// <empty>
// compile: test
"target/test-classes/BasicTests.class",
// test: junit-platform
"target/junit-platform/console-launcher.cmd.log",
"target/junit-platform/console-launcher.out.log"
"target/test-classes/JupiterTests.class",
"target/test-classes/TestNGTests.class",
// test: surefire
"target/surefire-reports/JupiterTests.txt",
"target/surefire-reports/TestNGTests.txt"
};

String[] emptyFiles = new String[] {
"target/junit-platform/console-launcher.err.log"
};

String log = new String(Files.readAllBytes(basedir.toPath().resolve("build.log")), "UTF-8");
String[] snippets = new String[] {
"[INFO] Launching JUnit Platform...",
"[INFO] Test run finished",
"[INFO] [ 2 containers found ]", // 1 engine + 1 class
"[INFO] [ 0 containers skipped ]",
"[INFO] [ 2 containers started ]",
"[INFO] [ 0 containers aborted ]",
"[INFO] [ 2 containers successful ]",
"[INFO] [ 0 containers failed ]",
"[INFO] [ 2 tests found ]", // 2 methods
"[INFO] [ 0 tests skipped ]",
"[INFO] [ 2 tests started ]",
"[INFO] [ 0 tests aborted ]",
"[INFO] [ 2 tests successful ]",
"[INFO] [ 0 tests failed ]",
"[DEBUG] Using configured provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider",
"[INFO] Running TestNGTests",
"[INFO] Running JupiterTests",
"[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0",
"[INFO] BUILD SUCCESS"
};

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/testng/junit5/NGClassDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static boolean isCandidate(Class<?> candidate) {
}

static NGClassDescriptor newContainerDescriptor(UniqueId container, Class<?> candidate) {
var id = container.append("testng-class", candidate.getTypeName());
UniqueId id = container.append("testng-class", candidate.getTypeName());
return new NGClassDescriptor(id, candidate.getSimpleName(), ClassSource.from(candidate));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/testng/junit5/NGMethodDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class NGMethodDescriptor extends AbstractTestDescriptor {

static NGMethodDescriptor newMethodDescriptor(UniqueId container, Method method) {
var id = container.append("testng-method", method.getName());
UniqueId id = container.append("testng-method", method.getName());
return new NGMethodDescriptor(id, method);
}

Expand Down
23 changes: 13 additions & 10 deletions src/main/java/org/testng/junit5/TestNGine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Optional;
import org.junit.platform.commons.util.ClassFilter;
import org.junit.platform.engine.EngineDiscoveryRequest;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.ExecutionRequest;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestEngine;
Expand All @@ -25,19 +26,21 @@ public String getId() {
}

public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId) {
var engine = new EngineDescriptor(uniqueId, ENGINE_DISPLAY_NAME);
EngineDescriptor engine = new EngineDescriptor(uniqueId, ENGINE_DISPLAY_NAME);
// inspect "request" selectors and filters passed by the user
// find TestNG-based test containers (classes) and tests (methods)
// wrap each in a new TestDescriptor
// add the created descriptor in a tree, below the "engine" descriptor
var filter = ClassFilter.of(buildClassNamePredicate(request), NGClassDescriptor::isCandidate);
var helper = new DiscoveryHelper(request, filter);
ClassFilter filter =
ClassFilter.of(buildClassNamePredicate(request), NGClassDescriptor::isCandidate);
DiscoveryHelper helper = new DiscoveryHelper(request, filter);
helper.discover(engine, this::handle);
return engine;
}

private void handle(EngineDescriptor engine, Class<?> candidate) {
var container = NGClassDescriptor.newContainerDescriptor(engine.getUniqueId(), candidate);
NGClassDescriptor container =
NGClassDescriptor.newContainerDescriptor(engine.getUniqueId(), candidate);
Arrays.stream(candidate.getMethods())
.filter(method -> method.isAnnotationPresent(Test.class))
.map(method -> NGMethodDescriptor.newMethodDescriptor(container.getUniqueId(), method))
Expand All @@ -49,18 +52,18 @@ private void handle(EngineDescriptor engine, Class<?> candidate) {
}

public void execute(ExecutionRequest request) {
var engine = request.getRootTestDescriptor();
var listener = request.getEngineExecutionListener();
TestDescriptor engine = request.getRootTestDescriptor();
EngineExecutionListener listener = request.getEngineExecutionListener();
listener.executionStarted(engine);
// iterate engine.getChildren() recursively and process each via:
// 1. tell the listener we started
// 2. try to execute the container/test and evaluate its result
// 3. tell the listener about the test execution result
for (var classDescriptor : engine.getChildren()) {
for (TestDescriptor classDescriptor : engine.getChildren()) {
listener.executionStarted(classDescriptor);
for (var methodDescriptor : classDescriptor.getChildren()) {
for (TestDescriptor methodDescriptor : classDescriptor.getChildren()) {
listener.executionStarted(methodDescriptor);
var result = executeMethod((NGMethodDescriptor) methodDescriptor);
TestExecutionResult result = executeMethod((NGMethodDescriptor) methodDescriptor);
listener.executionFinished(methodDescriptor, result);
}
listener.executionFinished(classDescriptor, TestExecutionResult.successful());
Expand All @@ -70,7 +73,7 @@ public void execute(ExecutionRequest request) {

private TestExecutionResult executeMethod(NGMethodDescriptor descriptor) {
try {
var target = descriptor.getMethod().getDeclaringClass().getConstructor().newInstance();
Object target = descriptor.getMethod().getDeclaringClass().getConstructor().newInstance();
descriptor.getMethod().invoke(target);
} catch (ReflectiveOperationException e) {
return TestExecutionResult.failed(e);
Expand Down

0 comments on commit 2a27b83

Please sign in to comment.