package lab; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** * Test case for the lab.Boolean class. * * @author Franck van Breugel */ public class BooleanTest { /** * Tests the constructor. */ @Test public void testConstructor() { Assertions.assertNotNull("Constructor returns null", new Boolean(true)); Assertions.assertNotNull("Constructor returns null", new Boolean(false)); } /** * Tests the booleanValue method. */ @Test public void testBooleanValue() { Assertions.assertEquals("booleanValue fails for true", true, (new Boolean(true)).booleanValue()); Assertions.assertEquals("booleanValue fails for false", false, (new Boolean(false)).booleanValue()); } /** * Test the constant TRUE. */ @Test public void testTrue() { Assertions.assertNotNull("The constant TRUE is null", Boolean.TRUE); Assertions.assertEquals("Value of TRUE is not true", true, Boolean.TRUE.booleanValue()); } /** * Tests that the compareTo method throws an exception. */ @Test public void testCompareToExceptionTrue() { Assertions.assertThrows(IllegalArgumentException.class, () -> { Boolean.TRUE.compareTo(null); }); } /** * Tests that the compareTo method throws an exception. */ @Test public void testCompareToExceptionFalse() { Assertions.assertThrows(IllegalArgumentException.class, () -> { final Boolean FALSE = new Boolean(false); FALSE.compareTo(null); }); } /** * Tests the compareTo method. */ @Test public void testCompareTo() { final Boolean FALSE = new Boolean(false); Assertions.assertEquals("Compare false to false", 0, FALSE.compareTo(FALSE)); Assertions.assertEquals("Compare true to true", 0, Boolean.TRUE.compareTo(Boolean.TRUE)); Assertions.assertTrue("Compare true to false", Boolean.TRUE.compareTo(FALSE) > 0); Assertions.assertTrue("Compare false to true", FALSE.compareTo(Boolean.TRUE) < 0); } }