Skip to content

Commit

Permalink
Saved code from current master
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Oct 27, 2015
1 parent 75a9126 commit 226ecd8
Show file tree
Hide file tree
Showing 28 changed files with 496 additions and 118 deletions.
2 changes: 2 additions & 0 deletions junit-commons/build.gradle
@@ -0,0 +1,2 @@
dependencies {
}
@@ -1,5 +1,5 @@


package org.junit.core.util; package org.junit.gen5.commons.util;


import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
Expand Down
@@ -1,5 +1,5 @@


package org.junit.core.util; package org.junit.gen5.commons.util;


import java.util.function.Supplier; import java.util.function.Supplier;


Expand Down
@@ -1,7 +1,7 @@
package org.junit.gen5.console; package org.junit.gen5.console;


import org.junit.gen5.launcher.Launcher; import org.junit.gen5.launcher.Launcher;
import org.junit.gen5.launcher.TestPlan; import org.junit.gen5.launcher.TestExecutionPlan;


public class Console { public class Console {


Expand All @@ -12,7 +12,7 @@ public static void main(String[] args) throws Exception {
Launcher launcher = new Launcher(); Launcher launcher = new Launcher();


// TODO Launch parameters: Provide configuration // TODO Launch parameters: Provide configuration
TestPlan testPlan = launcher.discoverTests(className); TestExecutionPlan testPlan = launcher.discoverTests(className);


// TODO Provide means to allow manipulation of test plan? // TODO Provide means to allow manipulation of test plan?
launcher.execute(testPlan); launcher.execute(testPlan);
Expand Down
Expand Up @@ -7,7 +7,7 @@ public interface Engine {


String getId(); String getId();


List<EngineTestDescription> discoverTests(String className); List<TestDescriptor> discoverTests(String className);


void execute(List<EngineTestDescription> testDescriptions) throws Exception; void execute(List<TestDescriptor> testDescriptions) throws Exception;
} }

This file was deleted.

@@ -1,5 +1,5 @@


package org.junit.core; package org.junit.gen5.engine;


import java.util.List; import java.util.List;


Expand All @@ -9,21 +9,21 @@
*/ */
public interface TestDescriptor { public interface TestDescriptor {


String getEngineId();

String getTestId();

/** /**
* Get the unique identifier (UID) for the described test. * Get the unique identifier (UID) for the described test.
* *
* <p>Uniqueness must hold across an entire test plan, regardless of * <p>Uniqueness must be guaranteed across an entire test plan,
* how many engines are used behind the scenes. * regardless of how many engines are used behind the scenes.
* *
* <p>The UID is simply the concatenation of the {@linkplain #getEngineId engine ID} * <p>The ID is simply the concatenation of the {@linkplain #getEngineId engine ID}
* and the {@linkplain #getTestId test ID} separated by a colon ({@code ":"}) * and the {@linkplain #getTestId test ID} separated by a colon ({@code ":"})
* &mdash; for example, {@code myEngine:test-description-unique-within-my-engine}. * &mdash; for example, {@code myEngine:test-description-unique-within-my-engine}.
*/ */
String getUniqueId(); String getId();

String getEngineId();

String getTestId();


String getDisplayName(); String getDisplayName();


Expand Down
1 change: 1 addition & 0 deletions junit-launcher/build.gradle
@@ -1,3 +1,4 @@
dependencies { dependencies {
compile(project(':junit-engine-api')) compile(project(':junit-engine-api'))
testCompile('junit:junit:4.12')
} }
20 changes: 10 additions & 10 deletions junit-launcher/src/main/java/org/junit/gen5/launcher/Launcher.java
Expand Up @@ -9,24 +9,24 @@
import java.util.stream.Collectors; import java.util.stream.Collectors;


import org.junit.gen5.engine.Engine; import org.junit.gen5.engine.Engine;
import org.junit.gen5.engine.EngineTestDescription; import org.junit.gen5.engine.TestDescriptor;


public class Launcher { public class Launcher {


private final Map<String, Map<TestIdentifier, EngineTestDescription>> testDescriptionsByEngine = new LinkedHashMap<>(); private final Map<String, Map<TestIdentifier, TestDescriptor>> testDescriptionsByEngine = new LinkedHashMap<>();


public TestPlan discoverTests(String className) { public TestExecutionPlan discoverTests(String className) {
TestPlan testPlan = new TestPlan(); TestExecutionPlan testPlan = new TestExecutionPlan();
for (Engine engine : discoverEngines()) { for (Engine engine : discoverEngines()) {
testPlan.addTestIdentifiers(discoverTests(className, engine)); testPlan.addTestIdentifiers(discoverTests(className, engine));
} }
return testPlan; return testPlan;
} }


private Set<TestIdentifier> discoverTests(String className, Engine engine) { private Set<TestIdentifier> discoverTests(String className, Engine engine) {
List<EngineTestDescription> discoveredTests = engine.discoverTests(className); List<TestDescriptor> discoveredTests = engine.discoverTests(className);


Map<TestIdentifier, EngineTestDescription> engineTestDescriptionsByTestId = new LinkedHashMap<>(); Map<TestIdentifier, TestDescriptor> engineTestDescriptionsByTestId = new LinkedHashMap<>();
discoveredTests.forEach(testDescription -> engineTestDescriptionsByTestId.put( discoveredTests.forEach(testDescription -> engineTestDescriptionsByTestId.put(
new TestIdentifier(engine.getId(), testDescription.getId(), testDescription.getDisplayName()), new TestIdentifier(engine.getId(), testDescription.getId(), testDescription.getDisplayName()),
testDescription)); testDescription));
Expand All @@ -36,22 +36,22 @@ private Set<TestIdentifier> discoverTests(String className, Engine engine) {
} }


// TODO no exceptions please // TODO no exceptions please
public void execute(TestPlan testPlan) throws Exception { public void execute(TestExecutionPlan testPlan) throws Exception {
for (Engine engine : discoverEngines()) { for (Engine engine : discoverEngines()) {
Map<TestIdentifier, EngineTestDescription> engineTestDescriptions = testDescriptionsByEngine Map<TestIdentifier, TestDescriptor> engineTestDescriptions = testDescriptionsByEngine
.get(engine.getId()); .get(engine.getId());
List<TestIdentifier> testIdentifiers = testPlan.getTestIdentifiers(); List<TestIdentifier> testIdentifiers = testPlan.getTestIdentifiers();
List<TestIdentifier> filtered = engineTestDescriptions.keySet().stream() List<TestIdentifier> filtered = engineTestDescriptions.keySet().stream()
.filter(testIdentifier -> testIdentifiers.contains(testIdentifier)).collect(Collectors.toList()); .filter(testIdentifier -> testIdentifiers.contains(testIdentifier)).collect(Collectors.toList());
List<EngineTestDescription> testDescriptions = new ArrayList<>(); List<TestDescriptor> testDescriptions = new ArrayList<>();
for (TestIdentifier testIdentifier : filtered) { for (TestIdentifier testIdentifier : filtered) {
testDescriptions.add(lookup(engine, testIdentifier)); testDescriptions.add(lookup(engine, testIdentifier));
} }
engine.execute(testDescriptions); engine.execute(testDescriptions);
} }
} }


private EngineTestDescription lookup(Engine engine, TestIdentifier testIdentifier) { private TestDescriptor lookup(Engine engine, TestIdentifier testIdentifier) {
return testDescriptionsByEngine.get(engine.getId()).get(testIdentifier); return testDescriptionsByEngine.get(engine.getId()).get(testIdentifier);
} }


Expand Down
@@ -0,0 +1,21 @@
package org.junit.gen5.launcher;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

// TODO make immutable?
// TODO name?
public class TestExecutionPlan {

private final List<TestIdentifier> testIdentifiers = new LinkedList<>();

public List<TestIdentifier> getTestIdentifiers() {
return testIdentifiers;
}

public void addTestIdentifiers(Collection<TestIdentifier> testDescriptions) {
this.testIdentifiers.addAll(testDescriptions);
}

}
73 changes: 63 additions & 10 deletions junit-launcher/src/main/java/org/junit/gen5/launcher/TestPlan.java
@@ -1,20 +1,73 @@

package org.junit.gen5.launcher; package org.junit.gen5.launcher;


import java.util.Collection; import java.nio.file.Path;
import java.util.LinkedList; import java.util.Map;
import java.util.List;


// TODO make immutable? /**
public class TestPlan { * @author Sam Brannen
* @since 5.0
*/
public final class TestPlan {


private final List<TestIdentifier> testIdentifiers = new LinkedList<>(); private TestPlan() {
/* no-op */
}


public List<TestIdentifier> getTestIdentifiers() { public static TestPlanBuilder builder() {
return testIdentifiers; return new TestPlanBuilder();
} }


public void addTestIdentifiers(Collection<TestIdentifier> testDescriptions) { public static final class TestPlanBuilder {
this.testIdentifiers.addAll(testDescriptions);
private TestPlanBuilder() {
/* no-op */
}

public TestPlanBuilder configuration(Map<String, String> parameters) {
return this;
}

public TestPlanBuilder classes(Class<?>... classes) {
return this;
}

public TestPlanBuilder classNames(String... classNames) {
return this;
}

public TestPlanBuilder packages(Package... packages) {
return this;
}

public TestPlanBuilder packageNames(String... packageNames) {
return this;
}

public TestPlanBuilder paths(Path... paths) {
return this;
}

public TestPlanBuilder fileNames(String... fileNames) {
return this;
}

public TestPlanBuilder descriptorIds(String... descriptorIds) {
return this;
}

public TestPlanBuilder includePatterns(String... patterns) {
return this;
}

public TestPlanBuilder excludePatterns(String... patterns) {
return this;
}

public TestPlan build() {
return new TestPlan();
}

} }


} }
@@ -0,0 +1,34 @@

package org.junit.gen5.launcher;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.HashMap;

import org.junit.Test;
import org.junit.gen5.launcher.TestPlan.TestPlanBuilder;

/**
* Unit tests for {@link TestPlanBuilder}.
*
* @author Sam Brannen
* @since 5.0
*/
public class TestPlanBuilderTests {

@Test
public void testPlanBuilderDemo() {
@SuppressWarnings("serial")
TestPlan testPlan = TestPlan.builder()
.configuration(new HashMap<String, String>(){{
put("category", "smoke");
}})
.packageNames("org.example.service.impl")
.includePatterns("*Tests")
.descriptorIds("junit5:org.example.UserTests#fullname()")
.build();

assertThat(testPlan).isNotNull();
}

}
2 changes: 2 additions & 0 deletions junit5-api/build.gradle
@@ -1,2 +1,4 @@
dependencies { dependencies {
compile(project(':open-test-alliance'))
compile(project(':junit-commons'))
} }
@@ -1,11 +1,10 @@

package org.junit.gen5.api;
package org.junit.core;


import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import java.util.function.Supplier; import java.util.function.Supplier;


import org.junit.core.util.ObjectUtils; import org.junit.gen5.commons.util.ObjectUtils;
import org.opentestalliance.AssertionFailedException; import org.opentestalliance.AssertionFailedError;


/** /**
* @author JUnit Community * @author JUnit Community
Expand All @@ -20,9 +19,9 @@ private Assertions() {


public static void fail(String message) { public static void fail(String message) {
if (message == null) { if (message == null) {
throw new AssertionFailedException(); throw new AssertionFailedError();
} }
throw new AssertionFailedException(message); throw new AssertionFailedError(message);
} }


public static void fail(Supplier<String> messageSupplier) { public static void fail(Supplier<String> messageSupplier) {
Expand Down Expand Up @@ -205,10 +204,10 @@ public static <T extends Throwable> T expectThrows(Class<T> expected, Executable
else { else {
String message = Assertions.format(expected.getName(), actual.getClass().getName(), String message = Assertions.format(expected.getName(), actual.getClass().getName(),
"unexpected exception type thrown;"); "unexpected exception type thrown;");
throw new AssertionFailedException(message, actual); throw new AssertionFailedError(message, actual);
} }
} }
throw new AssertionFailedException( throw new AssertionFailedError(
String.format("expected %s to be thrown, but nothing was thrown", expected.getName())); String.format("expected %s to be thrown, but nothing was thrown", expected.getName()));
} }


Expand Down
@@ -1,5 +1,4 @@

package org.junit.gen5.api;
package org.junit.core;


import org.opentestalliance.TestAbortedException; import org.opentestalliance.TestAbortedException;


Expand Down Expand Up @@ -30,6 +29,10 @@ public static void assumingThat(boolean condition, Executable executable) {
try { try {
executable.execute(); executable.execute();
} }
catch (AssertionError | RuntimeException e) {
// rethrow
throw e;
}
catch (Throwable e) { catch (Throwable e) {
// TODO Don't wrap Throwables such as OutOfMemoryError, etc. // TODO Don't wrap Throwables such as OutOfMemoryError, etc.
throw new RuntimeException("Wrapped exception thrown from Executable", e); throw new RuntimeException("Wrapped exception thrown from Executable", e);
Expand Down
@@ -1,5 +1,4 @@

package org.junit.gen5.api;
package org.junit.core;


/** /**
* @author Sam Brannen * @author Sam Brannen
Expand Down
15 changes: 15 additions & 0 deletions junit5-api/src/main/java/org/junit/gen5/api/Test.java
@@ -1,5 +1,20 @@
package org.junit.gen5.api; package org.junit.gen5.api;


import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Sam Brannen
* @since 5.0
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Test { public @interface Test {


String name() default "";

} }
1 change: 1 addition & 0 deletions junit5-engine/build.gradle
@@ -1,4 +1,5 @@
dependencies { dependencies {
compile(project(':junit-engine-api')) compile(project(':junit-engine-api'))
compile(project(':junit5-api')) compile(project(':junit5-api'))
testCompile("junit:junit:4.12")
} }

0 comments on commit 226ecd8

Please sign in to comment.