BAEL-1196: jUnit @Test Annotation (#3184)
* BAEL-1196: jUnit @Test Annotation * Fixed tests names as suggested. * Reduced visibility on test methods.
This commit is contained in:
parent
50b9b80730
commit
1a7e85ceed
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue