Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#40: Extract RunnerExecutor from JUnit4TestEngine
------------------------------------------------------------------------ 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
1 parent
4f5d6af
commit 2172817
Showing
2 changed files
with
52 additions
and
21 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
48 changes: 48 additions & 0 deletions
48
junit4-engine/src/main/java/org/junit/gen5/engine/junit4/execution/RunnerExecutor.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
/* | |||
* Copyright 2015-2016 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|||
package org.junit.gen5.engine.junit4.execution; | |||
|
|||
import static org.junit.gen5.engine.TestExecutionResult.failed; | |||
|
|||
import org.junit.gen5.engine.EngineExecutionListener; | |||
import org.junit.gen5.engine.TestExecutionResult; | |||
import org.junit.gen5.engine.junit4.descriptor.RunnerTestDescriptor; | |||
import org.junit.runner.JUnitCore; | |||
|
|||
public class RunnerExecutor { | |||
|
|||
private final EngineExecutionListener engineExecutionListener; | |||
|
|||
public RunnerExecutor(EngineExecutionListener engineExecutionListener) { | |||
this.engineExecutionListener = engineExecutionListener; | |||
} | |||
|
|||
public void execute(RunnerTestDescriptor runnerTestDescriptor) { | |||
TestRun testRun = new TestRun(runnerTestDescriptor); | |||
JUnitCore core = new JUnitCore(); | |||
core.addListener(new RunListenerAdapter(testRun, engineExecutionListener)); | |||
try { | |||
core.run(runnerTestDescriptor.getRunner()); | |||
} | |||
catch (Throwable t) { | |||
reportUnexpectedFailure(testRun, runnerTestDescriptor, failed(t)); | |||
} | |||
} | |||
|
|||
private void reportUnexpectedFailure(TestRun testRun, RunnerTestDescriptor runnerTestDescriptor, | |||
TestExecutionResult result) { | |||
if (testRun.isNotStarted(runnerTestDescriptor)) { | |||
engineExecutionListener.executionStarted(runnerTestDescriptor); | |||
} | |||
engineExecutionListener.executionFinished(runnerTestDescriptor, result); | |||
} | |||
|
|||
} |