Skip to content

Commit

Permalink
#40: Cleanup test
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
On behalf of the community, the JUnit Lambda Team thanks
msg systems ag (http://www.msg-systems.com) for supporting
the JUnit crowdfunding campaign!
------------------------------------------------------------------------
  • Loading branch information
marcphilipp committed Jan 4, 2016
1 parent 8da7676 commit 835ad40
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Expand Up @@ -30,9 +30,8 @@
public class ExecutionEventConditions {

@SafeVarargs
public static void assertRecordedExecutionEventsContainsExactly(
ExecutionEventRecordingEngineExecutionListener listener, Condition<? super ExecutionEvent>... conditions) {
List<ExecutionEvent> executionEvents = listener.getExecutionEvents();
public static void assertRecordedExecutionEventsContainsExactly(List<ExecutionEvent> executionEvents,
Condition<? super ExecutionEvent>... conditions) {
assertThat(executionEvents).hasSize(conditions.length);
for (int i = 0; i < conditions.length; i++) {
assertThat(executionEvents).has(conditions[i], atIndex(i));
Expand Down
Expand Up @@ -14,8 +14,11 @@
import static org.junit.gen5.engine.TestExecutionResultConditions.causeMessage;
import static org.junit.gen5.engine.TestPlanSpecification.*;

import java.util.List;

import org.junit.gen5.api.Test;
import org.junit.gen5.engine.EngineAwareTestDescriptor;
import org.junit.gen5.engine.ExecutionEvent;
import org.junit.gen5.engine.ExecutionEventRecordingEngineExecutionListener;
import org.junit.gen5.engine.ExecutionRequest;
import org.junit.gen5.engine.junit4.samples.EnclosedJUnit4TestCase;
Expand All @@ -27,15 +30,13 @@

class JUnit4TestEngineClassExecutionTests {

ExecutionEventRecordingEngineExecutionListener listener = new ExecutionEventRecordingEngineExecutionListener();

@Test
void executesPlainJUnit4TestCaseWithSingleTestWhichFails() {
Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;

execute(testClass);
List<ExecutionEvent> executionEvents = execute(testClass);

assertRecordedExecutionEventsContainsExactly(listener, //
assertRecordedExecutionEventsContainsExactly(executionEvents, //
event(engine(), started()), //
event(container(testClass.getName()), started()), //
event(test("failingTest"), started()), //
Expand All @@ -48,9 +49,9 @@ void executesPlainJUnit4TestCaseWithSingleTestWhichFails() {
void executesPlainJUnit4TestCaseWithTwoTests() {
Class<?> testClass = PlainJUnit4TestCaseWithTwoTests.class;

execute(testClass);
List<ExecutionEvent> executionEvents = execute(testClass);

assertRecordedExecutionEventsContainsExactly(listener, //
assertRecordedExecutionEventsContainsExactly(executionEvents, //
event(engine(), started()), //
event(container(testClass.getName()), started()), //
event(test("failingTest"), started()), //
Expand All @@ -65,9 +66,9 @@ void executesPlainJUnit4TestCaseWithTwoTests() {
void executesPlainJUnit4TestCaseWithFourTests() {
Class<?> testClass = PlainJUnit4TestCaseWithFourTests.class;

execute(testClass);
List<ExecutionEvent> executionEvents = execute(testClass);

assertRecordedExecutionEventsContainsExactly(listener, //
assertRecordedExecutionEventsContainsExactly(executionEvents, //
event(engine(), started()), //
event(container(testClass.getName()), started()), //
event(test("abortedTest"), started()), //
Expand All @@ -86,9 +87,9 @@ void executesEnclosedJUnit4TestCase() {
Class<?> testClass = EnclosedJUnit4TestCase.class;
Class<?> nestedClass = EnclosedJUnit4TestCase.NestedClass.class;

execute(testClass);
List<ExecutionEvent> executionEvents = execute(testClass);

assertRecordedExecutionEventsContainsExactly(listener, //
assertRecordedExecutionEventsContainsExactly(executionEvents, //
event(engine(), started()), //
event(container(testClass.getName()), started()), //
event(container(nestedClass.getName()), started()), //
Expand All @@ -104,9 +105,9 @@ void executesSuite() {
Class<?> junit4SuiteClass = JUnit4SuiteWithJUnit3SuiteWithSingleTestCase.class;
Class<?> testClass = PlainJUnit3TestCaseWithSingleTestWhichFails.class;

execute(junit4SuiteClass);
List<ExecutionEvent> executionEvents = execute(junit4SuiteClass);

assertRecordedExecutionEventsContainsExactly(listener, //
assertRecordedExecutionEventsContainsExactly(executionEvents, //
event(engine(), started()), //
event(container(junit4SuiteClass.getName()), started()), //
event(container("TestSuite with 1 tests"), started()), //
Expand All @@ -119,9 +120,11 @@ void executesSuite() {
event(engine(), finishedSuccessfully()));
}

private void execute(Class<?> testClass) {
private List<ExecutionEvent> execute(Class<?> testClass) {
JUnit4TestEngine engine = new JUnit4TestEngine();
EngineAwareTestDescriptor engineTestDescriptor = engine.discoverTests(build(forClass(testClass)));
ExecutionEventRecordingEngineExecutionListener listener = new ExecutionEventRecordingEngineExecutionListener();
engine.execute(new ExecutionRequest(engineTestDescriptor, listener));
return listener.getExecutionEvents();
}
}

0 comments on commit 835ad40

Please sign in to comment.