From e955c836adb16087392f1f29aa0b6c2d8a7ad5d6 Mon Sep 17 00:00:00 2001 From: Daniel Garrett Date: Mon, 6 Jul 2020 11:07:36 +0100 Subject: [PATCH 1/4] feat: add class to conditionally ignore unit tests --- .../ConditionallyIgnoreTestsUnitTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java 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 new file mode 100644 index 0000000000..af571eb808 --- /dev/null +++ b/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java @@ -0,0 +1,32 @@ +package com.baeldung.assume; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeThat; +import static org.junit.Assume.assumeTrue; + +import org.junit.Test; + +public class ConditionallyIgnoreTestsUnitTest { + + + @Test + public void whenAssumeThatCodeVersionIsNot1_thenIgnore() { + final int codeVersion = 1; + assumeThat(codeVersion, is(2)); + + assertEquals("hello", "HELLO".toLowerCase()); + } + + @Test + public void whenAssumeTrueOnCondition_thenIgnore() { + final int codeVersion = 1; + assumeTrue(isCodeVersion2(codeVersion)); + + assertEquals("hello", "HELLO".toLowerCase()); + } + + private boolean isCodeVersion2(final int codeVersion) { + return codeVersion == 2; + } +} From 278b5f8efa6d1ba238ba9761079529a12fcf56bc Mon Sep 17 00:00:00 2001 From: Daniel Garrett Date: Mon, 6 Jul 2020 11:15:35 +0100 Subject: [PATCH 2/4] fix: rename test --- .../com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 af571eb808..0a95ed4522 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 @@ -11,7 +11,7 @@ public class ConditionallyIgnoreTestsUnitTest { @Test - public void whenAssumeThatCodeVersionIsNot1_thenIgnore() { + public void whenAssumeThatCodeVersionIsNot2_thenIgnore() { final int codeVersion = 1; assumeThat(codeVersion, is(2)); From ecff38abf64bf603db9564f0640e705d847cd2d7 Mon Sep 17 00:00:00 2001 From: Daniel Garrett Date: Tue, 7 Jul 2020 16:14:30 +0100 Subject: [PATCH 3/4] feat: add test for assumeFalse --- .../assume/ConditionallyIgnoreTestsUnitTest.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 0a95ed4522..b5cc82d79d 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 @@ -2,8 +2,7 @@ package com.baeldung.assume; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; -import static org.junit.Assume.assumeThat; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.*; import org.junit.Test; @@ -26,6 +25,14 @@ public class ConditionallyIgnoreTestsUnitTest { 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; } From 1145918e228134b8cece158b4d24edc47eb586f7 Mon Sep 17 00:00:00 2001 From: Daniel Garrett Date: Mon, 13 Jul 2020 10:07:50 +0100 Subject: [PATCH 4/4] fix: replace * imports with single imports: --- .../com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 b5cc82d79d..0aa184f2e1 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 @@ -2,7 +2,9 @@ package com.baeldung.assume; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; -import static org.junit.Assume.*; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeThat; +import static org.junit.Assume.assumeTrue; import org.junit.Test;