diff --git a/testing-modules/junit-5/src/main/java/com/baeldung/junit5/bean/NumbersBean.java b/testing-modules/junit-5/src/main/java/com/baeldung/junit5/bean/NumbersBean.java new file mode 100644 index 0000000000..48730fd844 --- /dev/null +++ b/testing-modules/junit-5/src/main/java/com/baeldung/junit5/bean/NumbersBean.java @@ -0,0 +1,22 @@ +package com.baeldung.junit5.bean; + +/** + * Bean that contains utility methods to work with numbers. + * + * @author Donato Rimenti + * + */ +public class NumbersBean { + + /** + * Returns true if a number is even, false otherwise. + * + * @param number + * the number to check + * @return true if the argument is even, false otherwise + */ + public boolean isNumberEven(int number) { + return number % 2 == 0; + } + +} diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/bean/test/NumbersBeanUnitTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/bean/test/NumbersBeanUnitTest.java new file mode 100644 index 0000000000..0297d010e8 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/bean/test/NumbersBeanUnitTest.java @@ -0,0 +1,43 @@ +package com.baeldung.junit5.bean.test; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import com.baeldung.junit5.bean.NumbersBean; + +/** + * Test class for {@link NumbersBean}. + * + * @author Donato Rimenti + * + */ +public class NumbersBeanUnitTest { + + /** + * The bean to test. + */ + private NumbersBean bean = new NumbersBean(); + + /** + * Tests that when an even number is passed to + * {@link NumbersBean#isNumberEven(int)}, true is returned. + */ + @Test + void givenEvenNumber_whenCheckingIsNumberEven_thenTrue() { + boolean result = bean.isNumberEven(8); + + Assertions.assertTrue(result); + } + + /** + * Tests that when an odd number is passed to + * {@link NumbersBean#isNumberEven(int)}, false is returned. + */ + @Test + void givenOddNumber_whenCheckingIsNumberEven_thenFalse() { + boolean result = bean.isNumberEven(3); + + Assertions.assertFalse(result); + } + +}