1 package junitx.framework; 2 3 import java.util.List ; 4 import java.util.Vector ; 5 6 import junit.framework.AssertionFailedError; 7 import junit.framework.TestCase; 8 9 13 public class ListAssertTest extends TestCase { 14 15 public ListAssertTest(String name) { 16 super(name); 17 } 18 19 public void testEqualsSingleValue() { 20 List expected = new Vector (); 21 expected.add(new Integer (1)); 22 23 List actual = new Vector (); 24 actual.add(new Integer (1)); 25 26 ListAssert.assertEquals(expected, actual); 27 } 28 29 public void testEqualsMultipleValues() { 30 List expected = new Vector (); 31 expected.add(new Integer (1)); 32 expected.add(new Integer (2)); 33 34 List actual = new Vector (); 35 actual.add(new Integer (2)); 36 actual.add(new Integer (1)); 37 38 ListAssert.assertEquals(expected, actual); 39 } 40 41 public void testFailEqualsDifferentLength() { 42 List expected = new Vector (); 43 expected.add(new Integer (1)); 44 expected.add(new Integer (2)); 45 46 List actual = new Vector (); 47 actual.add(new Integer (1)); 48 49 try { 50 ListAssert.assertEquals(expected, actual); 51 } catch (AssertionFailedError e) { 52 assertEquals("expecting <2> in <1>", e.getMessage()); 53 return; 54 } 55 fail(); 56 } 57 58 public void testFailEqualsDifferentLength_2() { 59 List expected = new Vector (); 60 expected.add(new Integer (2)); 61 62 List actual = new Vector (); 63 actual.add(new Integer (2)); 64 actual.add(new Integer (1)); 65 66 try { 67 ListAssert.assertEquals(expected, actual); 68 } catch (AssertionFailedError e) { 69 assertEquals("[length] expected:<1> but was:<2>", e.getMessage()); 70 return; 71 } 72 fail(); 73 } 74 75 public void testContains() { 76 List expected = new Vector (); 77 expected.add(new Integer (1)); 78 expected.add(new Integer (2)); 79 80 ListAssert.assertContains(expected, new Integer (1)); 81 } 82 83 public void testFailContains() { 84 List expected = new Vector (); 85 expected.add(new Integer (1)); 86 expected.add(new Integer (2)); 87 88 try { 89 ListAssert.assertContains(expected, new Integer (3)); 90 } catch (AssertionFailedError e) { 91 assertEquals("expecting <3> in <1, 2>", e.getMessage()); 92 return; 93 } 94 fail(); 95 } 96 97 } 98 | Popular Tags |