Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests added, bugs fixed, javadocs added
- Loading branch information
Showing
3 changed files
with
346 additions
and
7 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
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,39 @@ | ||
package jmri.util; | ||
|
||
import java.awt.GraphicsEnvironment; | ||
import org.junit.AssumptionViolatedException; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* Test rule that only executes tests in presence of GUI environment. | ||
* Declare a field of this type in your class and annotate with {@link org.junit.Rule}: | ||
* <code> | ||
* <pre> | ||
* @Rule public AssumeGUIRule assumeGUI = new AssumeGUIRule(); | ||
* </pre> | ||
* </code> | ||
* All the tests in the class will be skipped in headless environment. | ||
* | ||
* @author Svata Dedic Copyright (c) 2019 | ||
*/ | ||
public class AssumeGUIRule implements TestRule { | ||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
if (GraphicsEnvironment.isHeadless()) { | ||
throw new AssumptionViolatedException("Headless environment. Skipping test!"); | ||
} else { | ||
base.evaluate(); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
public boolean hasGUI() { | ||
return !GraphicsEnvironment.isHeadless(); | ||
} | ||
} |
Oops, something went wrong.