Skip to content

Commit 1a7e85c

Browse files
aurasphereKevinGilmore
authored andcommitted
BAEL-1196: jUnit @test Annotation (eugenp#3184)
* BAEL-1196: jUnit @test Annotation * Fixed tests names as suggested. * Reduced visibility on test methods.
1 parent 50b9b80 commit 1a7e85c

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)