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