-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ARQ-2172): merged the same runner and rule code to avoid code d…
…uplication(#155)
- Loading branch information
1 parent
9a2130f
commit ac923bc
Showing
7 changed files
with
233 additions
and
143 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
junit/core/src/main/java/org/jboss/arquillian/junit/AdaptorManager.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,64 @@ | ||
package org.jboss.arquillian.junit; | ||
|
||
import org.jboss.arquillian.test.spi.TestRunnerAdaptor; | ||
import org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder; | ||
|
||
abstract class AdaptorManager { | ||
|
||
void initializeAdaptor() throws Exception { | ||
// first time we're being initialized | ||
if (!State.hasTestAdaptor()) { | ||
// no, initialization has been attempted before and failed, refuse | ||
// to do anything else | ||
if (State.hasInitializationException()) { | ||
// failed on suite level, ignore children | ||
// notifier.fireTestIgnored(getFailureDescription()); | ||
handleSuiteLevelFailure(State.getInitializationException()); | ||
} else { | ||
try { | ||
// ARQ-1742 If exceptions happen during boot | ||
TestRunnerAdaptor adaptor = TestRunnerAdaptorBuilder | ||
.build(); | ||
// don't set it if beforeSuite fails | ||
adaptor.beforeSuite(); | ||
State.testAdaptor(adaptor); | ||
} catch (Exception e) { | ||
// caught exception during BeforeSuite, mark this as failed | ||
State.caughtInitializationException(e); | ||
handleBeforeSuiteFailure(e); | ||
} | ||
} | ||
} | ||
|
||
if (State.hasTestAdaptor()) { | ||
setAdaptor(State.getTestAdaptor()); | ||
} | ||
} | ||
|
||
void shutdown(TestRunnerAdaptor adaptor) { | ||
State.runnerFinished(); | ||
try { | ||
if (State.isLastRunner()) { | ||
try { | ||
if (adaptor != null) { | ||
adaptor.afterSuite(); | ||
adaptor.shutdown(); | ||
} | ||
} finally { | ||
State.clean(); | ||
} | ||
} | ||
setAdaptor(null); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Could not run @AfterSuite", e); | ||
} | ||
} | ||
|
||
protected abstract void handleSuiteLevelFailure(Throwable initializationException); | ||
|
||
protected abstract void handleBeforeSuiteFailure(Exception e) throws Exception; | ||
|
||
protected abstract void setAdaptor(TestRunnerAdaptor testRunnerAdaptor); | ||
|
||
protected abstract TestRunnerAdaptor getAdaptor(); | ||
} |
47 changes: 47 additions & 0 deletions
47
junit/core/src/main/java/org/jboss/arquillian/junit/AdaptorManagerWithNotifier.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.jboss.arquillian.junit; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.Result; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunListener; | ||
import org.junit.runner.notification.RunNotifier; | ||
|
||
abstract class AdaptorManagerWithNotifier extends AdaptorManager { | ||
|
||
private final RunNotifier notifier; | ||
|
||
AdaptorManagerWithNotifier(RunNotifier notifier){ | ||
this.notifier = notifier; | ||
} | ||
|
||
void initializeAdaptor() { | ||
try { | ||
super.initializeAdaptor(); | ||
} catch (Exception e) { | ||
// this never happens | ||
} | ||
} | ||
|
||
void prepareDestroyAdaptorProcess(){ | ||
notifier.addListener(new RunListener() { | ||
@Override | ||
public void testRunFinished(Result result) throws Exception { | ||
shutdown(getAdaptor()); | ||
} | ||
}); | ||
} | ||
|
||
protected void handleSuiteLevelFailure(Throwable initializationException) { | ||
notifier.fireTestFailure( | ||
new Failure(getFailureDescription(), | ||
new RuntimeException( | ||
"Arquillian initialization has already been attempted, but failed. See previous exceptions for cause", | ||
initializationException))); | ||
} | ||
|
||
protected void handleBeforeSuiteFailure(Exception e) throws Exception { | ||
notifier.fireTestFailure(new Failure(getFailureDescription(), e)); | ||
} | ||
|
||
protected abstract Description getFailureDescription(); | ||
} |
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.