From 9f51e1c6e55bc55dbe69acf20179cc63fd7d0ddc Mon Sep 17 00:00:00 2001 From: Bruno Fontana Date: Tue, 22 Sep 2020 18:21:24 -0300 Subject: [PATCH 1/2] Assume Class examples redone. --- .../ConditionallyIgnoreTestsUnitTest.java | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java b/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java index 0aa184f2e1..b3fd5e3b2c 100644 --- a/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java +++ b/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java @@ -5,37 +5,55 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeThat; import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; +import static org.junit.Assume.assumeNoException; + import org.junit.Test; public class ConditionallyIgnoreTestsUnitTest { + @Test public void whenAssumeThatAndOSIsLinux_thenRunTest() { + assumeThat(getOsName(), is("Linux")); + assertEquals("run", "RUN".toLowerCase()); + } - @Test - public void whenAssumeThatCodeVersionIsNot2_thenIgnore() { - final int codeVersion = 1; - assumeThat(codeVersion, is(2)); + @Test public void whenAssumeTrueAndOSIsLinux_thenRunTest() { + final int codeVersion = 1; + assumeTrue(isExpectedOS(getOsName())); + 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 - public void whenAssumeTrueOnCondition_thenIgnore() { - final int codeVersion = 1; - assumeTrue(isCodeVersion2(codeVersion)); + private boolean isExpectedOS(final String osName) { + return "Linux".equals(osName); + } - assertEquals("hello", "HELLO".toLowerCase()); - } - - @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; - } + // This should use System.getProperty("os.name") in a real test. + private String getOsName() { + return "Linux"; + } } From 9a8f92de763b47f08928c69d11b7aab5e4e85b05 Mon Sep 17 00:00:00 2001 From: Bruno Fontana Date: Tue, 22 Sep 2020 20:54:25 -0300 Subject: [PATCH 2/2] Fixing formatting issues. --- .../ConditionallyIgnoreTestsUnitTest.java | 86 ++++++++++--------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java b/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java index b3fd5e3b2c..9f927310b3 100644 --- a/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java +++ b/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java @@ -13,47 +13,51 @@ import org.junit.Test; public class ConditionallyIgnoreTestsUnitTest { - @Test public void whenAssumeThatAndOSIsLinux_thenRunTest() { - assumeThat(getOsName(), is("Linux")); - assertEquals("run", "RUN".toLowerCase()); - } - - @Test public void whenAssumeTrueAndOSIsLinux_thenRunTest() { - final int codeVersion = 1; - assumeTrue(isExpectedOS(getOsName())); - assertEquals("run", "RUN".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); + @Test + public void whenAssumeThatAndOSIsLinux_thenRunTest() { + assumeThat(getOsName(), is("Linux")); + assertEquals("run", "RUN".toLowerCase()); } - assertEquals("run", "RUN".toLowerCase()); - } - private boolean isExpectedOS(final String osName) { - return "Linux".equals(osName); - } + @Test + public void whenAssumeTrueAndOSIsLinux_thenRunTest() { + assumeTrue(isExpectedOS(getOsName())); + assertEquals("run", "RUN".toLowerCase()); + } - // This should use System.getProperty("os.name") in a real test. - private String getOsName() { - return "Linux"; - } -} + @Test + public void whenAssumeFalseAndOSIsLinux_thenIgnore() { + assumeFalse(isExpectedOS(getOsName())); + assertEquals("run", "RUN".toLowerCase()); + } + + @Test + public void whenAssumeNotNullAndNotNullOSVersion_thenRun() { + 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()); + } + + private boolean isExpectedOS(final String osName) { + return "Linux".equals(osName); + } + + // This should use System.getProperty("os.name") in a real test. + private String getOsName() { + return "Linux"; + } +} \ No newline at end of file