Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension to disable headed tests in headless graphics environment (
- Loading branch information
Showing
6 changed files
with
67 additions
and
48 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
15 changes: 2 additions & 13 deletions
15
game-core/src/test/java/games/strategy/debug/error/reporting/ErrorReportWindowTest.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
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
26 changes: 26 additions & 0 deletions
26
...on/src/main/java/org/triplea/test/common/swing/DisabledInHeadlessGraphicsEnvironment.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,26 @@ | ||
package org.triplea.test.common.swing; | ||
|
||
import java.awt.GraphicsEnvironment; | ||
|
||
import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
import org.junit.jupiter.api.extension.ExecutionCondition; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
/** | ||
* An extension that disables tests when run in a headless graphics environment. | ||
*/ | ||
public final class DisabledInHeadlessGraphicsEnvironment implements ExecutionCondition { | ||
@Override | ||
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) { | ||
return evaluateExecutionCondition(GraphicsEnvironment.isHeadless()); | ||
} | ||
|
||
@VisibleForTesting | ||
static ConditionEvaluationResult evaluateExecutionCondition(final boolean headless) { | ||
return headless | ||
? ConditionEvaluationResult.disabled("Test disabled in headless graphics environment") | ||
: ConditionEvaluationResult.enabled(null); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...rc/test/java/org/triplea/test/common/swing/DisabledInHeadlessGraphicsEnvironmentTest.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,32 @@ | ||
package org.triplea.test.common.swing; | ||
|
||
import static com.github.npathai.hamcrestopt.OptionalMatchers.isEmpty; | ||
import static com.github.npathai.hamcrestopt.OptionalMatchers.isPresentAndIs; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.triplea.test.common.swing.DisabledInHeadlessGraphicsEnvironment.evaluateExecutionCondition; | ||
|
||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
|
||
final class DisabledInHeadlessGraphicsEnvironmentTest { | ||
@Nested | ||
final class EvaluateExecutionConditionTest { | ||
@Test | ||
void shouldReturnDisabledWhenGraphicsEnvironmentIsHeadless() { | ||
final ConditionEvaluationResult result = evaluateExecutionCondition(true); | ||
|
||
assertThat(result.isDisabled(), is(true)); | ||
assertThat(result.getReason(), isPresentAndIs("Test disabled in headless graphics environment")); | ||
} | ||
|
||
@Test | ||
void shouldReturnEnabledWhenGraphicsEnvironmentIsHeaded() { | ||
final ConditionEvaluationResult result = evaluateExecutionCondition(false); | ||
|
||
assertThat(result.isDisabled(), is(false)); | ||
assertThat(result.getReason(), isEmpty()); | ||
} | ||
} | ||
} |