import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.jupiter.api.Test;
public class BooleanConditionTest {
// Method that returns true
public boolean isEven(int number) {
return number % 2 == 0;
}
// Method that returns false
public boolean isOdd(int number) {
return number % 2 == 0;
}
@Test
public void testAssertTrue() {
// 4 is even, so isEven should return true
assertTrue(isEven(4), "Expected 4 to be even");
}
@Test
public void testAssertFalse() {
// 5 is odd, so isOdd should return false (since it returns true for even)
assertFalse(isOdd(5), "Expected 5 to be odd, so isOdd should be false here");
}
}This test class has two methods: isEven returns true if a number is even, and isOdd incorrectly returns true if a number is even (to demonstrate assertFalse).
The testAssertTrue method uses assertTrue to check that isEven(4) returns true because 4 is even.
The testAssertFalse method uses assertFalse to check that isOdd(5) returns false because 5 is odd and isOdd returns true only for even numbers (so it returns false for 5).
Static imports make the assertions easier to read. Each test has a clear message to explain failure if it happens.