Skip to content

Commit

Permalink
Launcher API umgebaut
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Oct 28, 2015
1 parent d52c835 commit cdaf668
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 36 deletions.
@@ -1,11 +1,11 @@
package org.junit.gen5.console;

import java.io.PrintStream;

import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestExecutionListener;
import org.junit.gen5.engine.TestPlanExecutionListener;

import java.io.PrintStream;

/**
* @author Stefan Bechtold
* @since 5.0
Expand All @@ -29,8 +29,8 @@ public ColoredPrintingTestListener(PrintStream out) {
}

@Override
public void testPlanExecutionStarted() {
out.println("Test execution started.");
public void testPlanExecutionStarted(int numberOfStaticTests) {
out.printf("Test execution started. Number of static tests: %d%n", numberOfStaticTests);
}

@Override
Expand All @@ -54,7 +54,7 @@ public void testPlanExecutionFinished() {
}

@Override
public void testFound(TestDescriptor testDescriptor) {
public void dynamicTestFound(TestDescriptor testDescriptor) {
out.print(ANSI_GREEN);
out.format("Test found: %s", testDescriptor.toString());
out.println(ANSI_RESET);
Expand Down
Expand Up @@ -4,7 +4,6 @@
import org.junit.gen5.engine.TestListenerRegistry;
import org.junit.gen5.engine.TestPlanSpecification;
import org.junit.gen5.launcher.Launcher;
import org.junit.gen5.launcher.TestPlan;

/**
* @author Stefan Bechtold
Expand All @@ -27,13 +26,10 @@ public static void main(String[] args) throws Throwable {
launcher.registerTestPlanExecutionListener(printingListener);
launcher.registerTestPlanExecutionListener(reportingListener);

TestPlanSpecification testPlanConfiguration = TestPlanSpecification.builder().classNames(args).build();

// TODO Launch parameters: Provide configuration
TestPlan testPlan = launcher.createTestPlanWithConfiguration(testPlanConfiguration);
TestPlanSpecification testPlanSpecification = TestPlanSpecification.builder().classNames(args).build();

// TODO Provide means to allow manipulation of test plan?
launcher.execute(testPlan);
launcher.execute(testPlanSpecification);
}

}
Expand Up @@ -29,7 +29,8 @@ public TestSummaryReportingTestListener(PrintStream out) {
}

@Override
public void testPlanExecutionStarted() {
public void testPlanExecutionStarted(int numberOfStaticTests) {
testsFound = numberOfStaticTests;
timeStarted = System.currentTimeMillis();
}

Expand Down Expand Up @@ -75,7 +76,7 @@ private void reportSummary(String msg) {
}

@Override
public void testFound(TestDescriptor testDescriptor) {
public void dynamicTestFound(TestDescriptor testDescriptor) {
testsFound++;
}

Expand Down
Expand Up @@ -8,7 +8,7 @@
*/
public interface TestExecutionListener {

default void testFound(TestDescriptor testDescriptor) {
default void dynamicTestFound(TestDescriptor testDescriptor) {
};

default void testStarted(TestDescriptor testDescriptor) {
Expand Down
Expand Up @@ -8,7 +8,7 @@
*/
public interface TestPlanExecutionListener {

default void testPlanExecutionStarted() {
default void testPlanExecutionStarted(int numberOfStaticTests) {
};

default void testPlanExecutionPaused() {
Expand Down
19 changes: 13 additions & 6 deletions junit-launcher/src/main/java/org/junit/gen5/launcher/Launcher.java
@@ -1,14 +1,14 @@

package org.junit.gen5.launcher;

import static org.junit.gen5.engine.TestListenerRegistry.*;
import static org.junit.gen5.launcher.TestEngineRegistry.*;

import org.junit.gen5.engine.TestEngine;
import org.junit.gen5.engine.TestListenerRegistry;
import org.junit.gen5.engine.TestPlanExecutionListener;
import org.junit.gen5.engine.TestPlanSpecification;

import static org.junit.gen5.engine.TestListenerRegistry.notifyTestPlanExecutionListeners;
import static org.junit.gen5.launcher.TestEngineRegistry.lookupAllTestEngines;

/**
* @author Stefan Bechtold
* @author Sam Brannen
Expand All @@ -21,16 +21,23 @@ public void registerTestPlanExecutionListener(TestPlanExecutionListener testList
TestListenerRegistry.registerTestPlanExecutionListener(testListener);
}

public TestPlan createTestPlanWithConfiguration(TestPlanSpecification specification) {
public TestPlan discover(TestPlanSpecification specification) {
TestPlan testPlan = new TestPlan();
for (TestEngine testEngine : lookupAllTestEngines()) {
testPlan.addTests(testEngine.discoverTests(specification));
}
return testPlan;
}

public void execute(TestPlan testPlan) {
notifyTestPlanExecutionListeners(TestPlanExecutionListener::testPlanExecutionStarted);
public void execute(TestPlanSpecification specification) {
TestPlan plan = discover(specification);
execute(plan);
}

private void execute(TestPlan testPlan) {
notifyTestPlanExecutionListeners(
testPlanExecutionListener -> testPlanExecutionListener.testPlanExecutionStarted(testPlan.getTests().size())
);

for (TestEngine testEngine : lookupAllTestEngines()) {
testEngine.execute(testPlan.getAllTestsForTestEngine(testEngine));
Expand Down
@@ -1,23 +1,23 @@
package org.junit.gen5.engine.junit5;

import static java.lang.String.format;
import static org.junit.gen5.commons.util.ReflectionUtils.invokeMethod;
import static org.junit.gen5.commons.util.ReflectionUtils.newInstance;
import static org.junit.gen5.engine.TestListenerRegistry.notifyTestExecutionListeners;
import org.junit.gen5.api.Test;
import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestEngine;
import org.junit.gen5.engine.TestPlanSpecification;
import org.opentestalliance.TestAbortedException;
import org.opentestalliance.TestSkippedException;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.gen5.api.Test;
import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestEngine;
import org.junit.gen5.engine.TestPlanSpecification;
import org.opentestalliance.TestAbortedException;
import org.opentestalliance.TestSkippedException;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static org.junit.gen5.commons.util.ReflectionUtils.invokeMethod;
import static org.junit.gen5.commons.util.ReflectionUtils.newInstance;
import static org.junit.gen5.engine.TestListenerRegistry.notifyTestExecutionListeners;

public class JUnit5TestEngine implements TestEngine {
// TODO - SBE - could be replace by JUnit5TestEngine.class.getCanonicalName();
Expand All @@ -37,14 +37,12 @@ public List<TestDescriptor> discoverTests(TestPlanSpecification specification) {
.flatMap(Arrays::stream)
.filter(method -> method.isAnnotationPresent(Test.class))
.map(method -> new JavaTestDescriptor(getId(), method))
.peek(testDescriptor -> notifyTestExecutionListeners(testListener -> testListener.testFound(testDescriptor)))
.collect(Collectors.toList());
.collect(toList());

testDescriptors.addAll(
specification.getUniqueIds().stream()
.map(JavaTestDescriptor::from)
.peek(testDescriptor -> notifyTestExecutionListeners(testListener -> testListener.testFound(testDescriptor)))
.collect(Collectors.toList())
.collect(toList())
);

return testDescriptors;
Expand Down

0 comments on commit cdaf668

Please sign in to comment.