File tree Expand file tree Collapse file tree
testing-modules/junit-5/src
main/java/com/baeldung/junit5/bean
test/java/com/baeldung/junit5/bean/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .junit5 .bean ;
2+
3+ /**
4+ * Bean that contains utility methods to work with numbers.
5+ *
6+ * @author Donato Rimenti
7+ *
8+ */
9+ public class NumbersBean {
10+
11+ /**
12+ * Returns true if a number is even, false otherwise.
13+ *
14+ * @param number
15+ * the number to check
16+ * @return true if the argument is even, false otherwise
17+ */
18+ public boolean isNumberEven (int number ) {
19+ return number % 2 == 0 ;
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .junit5 .bean .test ;
2+
3+ import org .junit .jupiter .api .Assertions ;
4+ import org .junit .jupiter .api .Test ;
5+
6+ import com .baeldung .junit5 .bean .NumbersBean ;
7+
8+ /**
9+ * Test class for {@link NumbersBean}.
10+ *
11+ * @author Donato Rimenti
12+ *
13+ */
14+ public class NumbersBeanUnitTest {
15+
16+ /**
17+ * The bean to test.
18+ */
19+ private NumbersBean bean = new NumbersBean ();
20+
21+ /**
22+ * Tests that when an even number is passed to
23+ * {@link NumbersBean#isNumberEven(int)}, true is returned.
24+ */
25+ @ Test
26+ void givenEvenNumber_whenCheckingIsNumberEven_thenTrue () {
27+ boolean result = bean .isNumberEven (8 );
28+
29+ Assertions .assertTrue (result );
30+ }
31+
32+ /**
33+ * Tests that when an odd number is passed to
34+ * {@link NumbersBean#isNumberEven(int)}, false is returned.
35+ */
36+ @ Test
37+ void givenOddNumber_whenCheckingIsNumberEven_thenFalse () {
38+ boolean result = bean .isNumberEven (3 );
39+
40+ Assertions .assertFalse (result );
41+ }
42+
43+ }
You can’t perform that action at this time.
0 commit comments