import static org.junit.Assert.*; import org.junit.*; import java.util.*; /** * JUnit Test Cases for Min * see also Min.java and AllTests.java * @author Paul Ammann * */ public class MinTest { List list; /** * Sets up the test fixture. (Called before every test case method.) */ @Before public void setUp() { list = new Vector(); } /** * Tears down the test fixture. (Called after every test case method.) */ @After public void tearDown() { list = null; } /** * Tests null list argument */ @Test(expected = NullPointerException.class) public void testForNullList() { Object obj = Min.min(null); } /** * Tests null list element (first and only position) */ @Test(expected = NullPointerException.class) public void testForNullElement1() { list.add(null); Object obj = Min.min(list); } /** * Tests null list element (first of several positions) */ @Test(expected = NullPointerException.class) public void testForNullElement2() { list.add(null); list.add("cat"); Object obj = Min.min(list); } /** * Tests null list element (second of several positions) */ @Test(expected = NullPointerException.class) public void testForNullElement3() { list.add("cat"); list.add(null); list.add("dog"); Object obj = Min.min(list); } /** * Tests incomparable elements */ @Test(expected = ClassCastException.class) public void testMutuallyIncomparable() { list.add("cat"); list.add("dog"); list.add(1); Object obj = Min.min(list); } /** /** * Tests empty list */ @Test(expected = IllegalArgumentException.class) public void testEmptyList() { Object obj = Min.min(list); } /** * Tests for normal case with single element list */ @Test public void testSingleElement() { list.add("cat"); Object obj = Min.min(list); assertTrue(obj.equals("cat")); } /** * Tests for normal case with double element list */ @Test public void testDoubleElement() { list.add("dog"); list.add("cat"); Object obj = Min.min(list); assertTrue(obj.equals("cat")); } }