forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce unit tests for operating system conditions
This commit introduces dedicated unit tests for EnabledOnOsCondition and DisabledOnOsCondition. Issue: junit-team#1280
- Loading branch information
Showing
4 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
166 changes: 166 additions & 0 deletions
166
...iter-engine/src/test/java/org/junit/jupiter/api/condition/DisabledOnOsConditionTests.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,166 @@ | ||
/* | ||
* Copyright 2015-2018 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 v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.condition; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.condition.EnabledOnOsIntegrationTests.onLinux; | ||
import static org.junit.jupiter.api.condition.EnabledOnOsIntegrationTests.onMac; | ||
import static org.junit.jupiter.api.condition.EnabledOnOsIntegrationTests.onSolaris; | ||
import static org.junit.jupiter.api.condition.EnabledOnOsIntegrationTests.onWindows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExecutionCondition; | ||
import org.junit.platform.commons.util.PreconditionViolationException; | ||
|
||
/** | ||
* Unit tests for {@link DisabledOnOsCondition}. | ||
* | ||
* <p>Note that test method names MUST match the test method names in | ||
* {@link DisabledOnOsIntegrationTests}. | ||
* | ||
* @since 5.1 | ||
*/ | ||
class DisabledOnOsConditionTests extends AbstractExecutionConditionTests { | ||
|
||
@Override | ||
protected ExecutionCondition getExecutionCondition() { | ||
return new DisabledOnOsCondition(); | ||
} | ||
|
||
@Override | ||
protected Class<?> getTestClass() { | ||
return DisabledOnOsIntegrationTests.class; | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#enabledBecauseAnnotationIsNotPresent() | ||
*/ | ||
@Test | ||
void enabledBecauseAnnotationIsNotPresent() { | ||
evaluateCondition(); | ||
assertEnabled(); | ||
assertReasonContains("@DisabledOnOs is not present"); | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#missingOsDeclaration() | ||
*/ | ||
@Test | ||
void missingOsDeclaration() { | ||
Exception exception = assertThrows(PreconditionViolationException.class, this::evaluateCondition); | ||
assertThat(exception).hasMessageContaining("You must declare at least one OS"); | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#disabledOnEveryOs() | ||
*/ | ||
@Test | ||
void disabledOnEveryOs() { | ||
evaluateCondition(); | ||
assertDisabledOnCurrentOs(); | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#linux() | ||
*/ | ||
@Test | ||
void linux() { | ||
evaluateCondition(); | ||
if (onLinux()) { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
else { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#macOs() | ||
*/ | ||
@Test | ||
void macOs() { | ||
evaluateCondition(); | ||
if (onMac()) { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
else { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#macOsWithComposedAnnotation() | ||
*/ | ||
@Test | ||
void macOsWithComposedAnnotation() { | ||
evaluateCondition(); | ||
if (onMac()) { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
else { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#windows() | ||
*/ | ||
@Test | ||
void windows() { | ||
evaluateCondition(); | ||
if (onWindows()) { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
else { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#solaris() | ||
*/ | ||
@Test | ||
void solaris() { | ||
evaluateCondition(); | ||
if (onSolaris()) { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
else { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see DisabledOnOsIntegrationTests#other() | ||
*/ | ||
@Test | ||
void other() { | ||
evaluateCondition(); | ||
if (onLinux() || onMac() || onSolaris() || onWindows()) { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
else { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
private void assertEnabledOnCurrentOs() { | ||
assertEnabled(); | ||
assertReasonContains("Enabled on operating system: " + System.getProperty("os.name")); | ||
} | ||
|
||
private void assertDisabledOnCurrentOs() { | ||
assertDisabled(); | ||
assertReasonContains("Disabled on operating system: " + System.getProperty("os.name")); | ||
} | ||
|
||
} |
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
166 changes: 166 additions & 0 deletions
166
...piter-engine/src/test/java/org/junit/jupiter/api/condition/EnabledOnOsConditionTests.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,166 @@ | ||
/* | ||
* Copyright 2015-2018 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 v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.condition; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.condition.EnabledOnOsIntegrationTests.onLinux; | ||
import static org.junit.jupiter.api.condition.EnabledOnOsIntegrationTests.onMac; | ||
import static org.junit.jupiter.api.condition.EnabledOnOsIntegrationTests.onSolaris; | ||
import static org.junit.jupiter.api.condition.EnabledOnOsIntegrationTests.onWindows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExecutionCondition; | ||
import org.junit.platform.commons.util.PreconditionViolationException; | ||
|
||
/** | ||
* Unit tests for {@link EnabledOnOsCondition}. | ||
* | ||
* <p>Note that test method names MUST match the test method names in | ||
* {@link EnabledOnOsIntegrationTests}. | ||
* | ||
* @since 5.1 | ||
*/ | ||
class EnabledOnOsConditionTests extends AbstractExecutionConditionTests { | ||
|
||
@Override | ||
protected ExecutionCondition getExecutionCondition() { | ||
return new EnabledOnOsCondition(); | ||
} | ||
|
||
@Override | ||
protected Class<?> getTestClass() { | ||
return EnabledOnOsIntegrationTests.class; | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#enabledBecauseAnnotationIsNotPresent() | ||
*/ | ||
@Test | ||
void enabledBecauseAnnotationIsNotPresent() { | ||
evaluateCondition(); | ||
assertEnabled(); | ||
assertReasonContains("@EnabledOnOs is not present"); | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#missingOsDeclaration() | ||
*/ | ||
@Test | ||
void missingOsDeclaration() { | ||
Exception exception = assertThrows(PreconditionViolationException.class, this::evaluateCondition); | ||
assertThat(exception).hasMessageContaining("You must declare at least one OS"); | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#enabledOnEveryOs() | ||
*/ | ||
@Test | ||
void enabledOnEveryOs() { | ||
evaluateCondition(); | ||
assertEnabledOnCurrentOs(); | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#linux() | ||
*/ | ||
@Test | ||
void linux() { | ||
evaluateCondition(); | ||
if (onLinux()) { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
else { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#macOs() | ||
*/ | ||
@Test | ||
void macOs() { | ||
evaluateCondition(); | ||
if (onMac()) { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
else { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#macOsWithComposedAnnotation() | ||
*/ | ||
@Test | ||
void macOsWithComposedAnnotation() { | ||
evaluateCondition(); | ||
if (onMac()) { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
else { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#windows() | ||
*/ | ||
@Test | ||
void windows() { | ||
evaluateCondition(); | ||
if (onWindows()) { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
else { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#solaris() | ||
*/ | ||
@Test | ||
void solaris() { | ||
evaluateCondition(); | ||
if (onSolaris()) { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
else { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
/** | ||
* @see EnabledOnOsIntegrationTests#other() | ||
*/ | ||
@Test | ||
void other() { | ||
evaluateCondition(); | ||
if (onLinux() || onMac() || onSolaris() || onWindows()) { | ||
assertDisabledOnCurrentOs(); | ||
} | ||
else { | ||
assertEnabledOnCurrentOs(); | ||
} | ||
} | ||
|
||
private void assertEnabledOnCurrentOs() { | ||
assertEnabled(); | ||
assertReasonContains("Enabled on operating system: " + System.getProperty("os.name")); | ||
} | ||
|
||
private void assertDisabledOnCurrentOs() { | ||
assertDisabled(); | ||
assertReasonContains("Disabled on operating system: " + System.getProperty("os.name")); | ||
} | ||
|
||
} |
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