Assume Class examples redone.
This commit is contained in:
parent
10e7aaed73
commit
9f51e1c6e5
@ -5,37 +5,55 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assume.assumeFalse;
|
import static org.junit.Assume.assumeFalse;
|
||||||
import static org.junit.Assume.assumeThat;
|
import static org.junit.Assume.assumeThat;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
import static org.junit.Assume.assumeNotNull;
|
||||||
|
import static org.junit.Assume.assumeNoException;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ConditionallyIgnoreTestsUnitTest {
|
public class ConditionallyIgnoreTestsUnitTest {
|
||||||
|
|
||||||
|
@Test public void whenAssumeThatAndOSIsLinux_thenRunTest() {
|
||||||
|
assumeThat(getOsName(), is("Linux"));
|
||||||
|
assertEquals("run", "RUN".toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void whenAssumeTrueAndOSIsLinux_thenRunTest() {
|
||||||
public void whenAssumeThatCodeVersionIsNot2_thenIgnore() {
|
final int codeVersion = 1;
|
||||||
final int codeVersion = 1;
|
assumeTrue(isExpectedOS(getOsName()));
|
||||||
assumeThat(codeVersion, is(2));
|
assertEquals("run", "RUN".toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
assertEquals("hello", "HELLO".toLowerCase());
|
@Test public void whenAssumeFalseAndOSIsLinux_thenIgnore() {
|
||||||
|
assumeFalse(isExpectedOS(getOsName()));
|
||||||
|
assertEquals("run", "RUN".toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test public void whenAssumeNotNullAndNotNullOSVersion_thenIgnore() {
|
||||||
|
assumeNotNull(getOsName());
|
||||||
|
assertEquals("run", "RUN".toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Let's use a different example here.
|
||||||
|
*/
|
||||||
|
@Test public void whenAssumeNoExceptionAndExceptionThrown_thenIgnore() {
|
||||||
|
assertEquals("everything ok", "EVERYTHING OK".toLowerCase());
|
||||||
|
String t = null;
|
||||||
|
try {
|
||||||
|
t.charAt(0);
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
assumeNoException(npe);
|
||||||
}
|
}
|
||||||
|
assertEquals("run", "RUN".toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
private boolean isExpectedOS(final String osName) {
|
||||||
public void whenAssumeTrueOnCondition_thenIgnore() {
|
return "Linux".equals(osName);
|
||||||
final int codeVersion = 1;
|
}
|
||||||
assumeTrue(isCodeVersion2(codeVersion));
|
|
||||||
|
|
||||||
assertEquals("hello", "HELLO".toLowerCase());
|
// This should use System.getProperty("os.name") in a real test.
|
||||||
}
|
private String getOsName() {
|
||||||
|
return "Linux";
|
||||||
@Test
|
}
|
||||||
public void whenAssumeFalseOnCondition_thenIgnore() {
|
|
||||||
final int codeVersion = 2;
|
|
||||||
assumeFalse(isCodeVersion2(codeVersion));
|
|
||||||
|
|
||||||
assertEquals("hello", "HELLO".toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isCodeVersion2(final int codeVersion) {
|
|
||||||
return codeVersion == 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user