1 package jimm.datavision.test; 2 import jimm.datavision.SectionArea; 3 import jimm.datavision.Section; 4 import jimm.datavision.Report; 5 import java.util.List ; 6 import junit.framework.TestCase; 7 import junit.framework.TestSuite; 8 import junit.framework.Test; 9 10 15 public class SectionAreaTest extends TestCase { 16 17 protected SectionArea area; 18 protected Section sect; 19 protected Report report; 20 21 public static Test suite() { 22 return new TestSuite(SectionAreaTest.class); 23 } 24 25 public SectionAreaTest(String name) { 26 super(name); 27 } 28 29 public void setUp() { 30 area = new SectionArea(SectionArea.DETAIL); 31 report = new Report(); 32 sect = new Section(report); 33 } 34 35 public void testBasicStuff() { 36 assertEquals(SectionArea.DETAIL, area.getArea()); 37 } 38 39 public void testIsDetail() { 40 assertTrue(area.isDetail()); 41 42 area = new SectionArea(SectionArea.REPORT_HEADER); 43 assertTrue(!area.isDetail()); 44 } 45 46 public void testListBehavior() { 47 assertNull(sect.getArea()); 48 assertEquals(0, area.size()); 49 50 area.add(sect); 51 assertEquals(1, area.size()); 52 assertSame(area, sect.getArea()); 53 assertEquals(0, area.indexOf(sect)); 54 assertSame(sect, area.first()); 55 56 Section sect2 = new Section(report); 57 area.add(sect2); 58 assertEquals(2, area.size()); 59 assertSame(area, sect2.getArea()); 60 assertEquals(1, area.indexOf(sect2)); 61 assertSame(sect, area.first()); 62 63 Section sect3 = new Section(report); 64 area.insertAfter(sect3, sect); 65 assertEquals(1, area.indexOf(sect3)); 66 assertEquals(2, area.indexOf(sect2)); 67 } 68 69 public void testInsertAfter() { 70 area.add(sect); 71 Section newSection = area.insertAfter(null, sect); 72 73 assertNotSame(newSection, sect); 74 assertEquals(1, area.indexOf(newSection)); 75 assertEquals(area.getName(), newSection.getName()); 76 assertSame(area, newSection.getArea()); 77 } 78 79 public void testRemove() { 80 area.add(sect); 81 Section newSection = area.insertAfter(null, sect); 82 83 assertEquals(2, area.size()); 84 area.remove(sect); 85 assertNull(sect.getArea()); 86 assertEquals(1, area.size()); 87 assertSame(newSection, area.first()); 88 89 area.remove(newSection); 90 assertNull(newSection.getArea()); 91 assertEquals(0, area.size()); 92 } 93 94 public void testIllegalArg() { 95 try { 96 area.insertAfter(null, null); 97 fail("should have thrown IllegalArgumentException"); 98 } 99 catch (IllegalArgumentException e) { 100 assertTrue(true); 101 } 102 } 103 104 public void testSectionDelegation() { 105 assertNull(sect.getName()); 106 107 area.add(sect); 108 assertEquals(area.getName(), sect.getName()); 109 assertEquals(area.isDetail(), sect.isDetail()); 110 } 111 112 public void testUnmodifiable() { 113 area.add(sect); 114 List sections = area.sections(); 115 try { 116 sections.add(new Section(report)); 117 } 118 catch (UnsupportedOperationException e) { 119 assertTrue(true); 120 } 121 } 122 123 public void testClear() { 124 Section sect2 = new Section(report); 125 area.add(sect); 126 area.add(sect2); 127 assertEquals(2, area.size()); 128 129 area.clear(); 130 assertEquals(0, area.size()); 131 132 assertNull(sect.getArea()); 133 assertNull(sect2.getArea()); 134 } 135 136 public static void main(String [] args) { 137 junit.textui.TestRunner.run(suite()); 138 System.exit(0); 139 } 140 141 } 142 | Popular Tags |