Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spike tree-based "implementation" of JUnit5 engine
- Loading branch information
1 parent
5eb4642
commit 28ffd5e
Showing
17 changed files
with
533 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
junit-engine-api/src/main/java/org/junit/gen5/engine/Child.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
package org.junit.gen5.engine; | ||
|
||
public interface Child { | ||
|
||
Context execute(Context context) throws Throwable; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
junit-engine-api/src/main/java/org/junit/gen5/engine/Context.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
package org.junit.gen5.engine; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Context { | ||
|
||
private final Map<String, Object> map; | ||
|
||
public Context() { | ||
this(new HashMap<>()); | ||
} | ||
|
||
private Context(Map<String, Object> map) { | ||
this.map = map; | ||
} | ||
|
||
public Context with(String key, Object value) { | ||
Map<String, Object> newMap = new HashMap<>(map); | ||
newMap.put(key, value); | ||
return new Context(newMap); | ||
} | ||
|
||
public <T> T get(String key, Class<T> clazz) { | ||
return clazz.cast(map.get(key)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
junit-engine-api/src/main/java/org/junit/gen5/engine/MutableTestDescriptor.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
junit-engine-api/src/main/java/org/junit/gen5/engine/Parent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
package org.junit.gen5.engine; | ||
|
||
public interface Parent { | ||
|
||
Context beforeAll(Context context); | ||
|
||
Context afterAll(Context context); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
junit-engine-api/src/main/java/org/junit/gen5/engine/TreeBasedTestEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
package org.junit.gen5.engine; | ||
|
||
public abstract class TreeBasedTestEngine implements TestEngine { | ||
|
||
@Override | ||
public abstract TestDescriptor discoverTests(TestPlanSpecification specification); | ||
|
||
@Override | ||
public final void execute(ExecutionRequest request) { | ||
try { | ||
TestDescriptor rootTestDescriptor = request.getRootTestDescriptor(); | ||
executeAll(rootTestDescriptor, request.getEngineExecutionListener(), new Context()); | ||
} | ||
catch (Exception e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private <T> void executeAll(TestDescriptor parentDescriptor, EngineExecutionListener listener, | ||
Context parentContext) throws Exception { | ||
Context context = parentContext; | ||
if (parentDescriptor instanceof Parent) { | ||
context = ((Parent) parentDescriptor).beforeAll(context); | ||
} | ||
for (TestDescriptor childDescriptor : parentDescriptor.getChildren()) { | ||
if (childDescriptor instanceof Child) { | ||
Child child = (Child) childDescriptor; | ||
try { | ||
listener.testStarted(childDescriptor); | ||
context = child.execute(context); | ||
listener.testSucceeded(childDescriptor); | ||
} | ||
catch (Throwable t) { | ||
listener.testFailed(childDescriptor, t); | ||
context = context.with("Throwable", t); | ||
} | ||
} | ||
executeAll(childDescriptor, listener, context); | ||
} | ||
if (parentDescriptor instanceof Parent) { | ||
context = ((Parent) parentDescriptor).afterAll(context); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.