001: package jimm.datavision.test;
002:
003: import jimm.datavision.SectionArea;
004: import jimm.datavision.Section;
005: import jimm.datavision.Report;
006: import java.util.List;
007: import junit.framework.TestCase;
008: import junit.framework.TestSuite;
009: import junit.framework.Test;
010:
011: /**
012: * Tests {@link SectionArea}.
013: *
014: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
015: */
016: public class SectionAreaTest extends TestCase {
017:
018: protected SectionArea area;
019: protected Section sect;
020: protected Report report;
021:
022: public static Test suite() {
023: return new TestSuite(SectionAreaTest.class);
024: }
025:
026: public SectionAreaTest(String name) {
027: super (name);
028: }
029:
030: public void setUp() {
031: area = new SectionArea(SectionArea.DETAIL);
032: report = new Report();
033: sect = new Section(report);
034: }
035:
036: public void testBasicStuff() {
037: assertEquals(SectionArea.DETAIL, area.getArea());
038: }
039:
040: public void testIsDetail() {
041: assertTrue(area.isDetail());
042:
043: area = new SectionArea(SectionArea.REPORT_HEADER);
044: assertTrue(!area.isDetail());
045: }
046:
047: public void testListBehavior() {
048: assertNull(sect.getArea());
049: assertEquals(0, area.size());
050:
051: area.add(sect);
052: assertEquals(1, area.size());
053: assertSame(area, sect.getArea());
054: assertEquals(0, area.indexOf(sect));
055: assertSame(sect, area.first());
056:
057: Section sect2 = new Section(report);
058: area.add(sect2);
059: assertEquals(2, area.size());
060: assertSame(area, sect2.getArea());
061: assertEquals(1, area.indexOf(sect2));
062: assertSame(sect, area.first());
063:
064: Section sect3 = new Section(report);
065: area.insertAfter(sect3, sect);
066: assertEquals(1, area.indexOf(sect3));
067: assertEquals(2, area.indexOf(sect2));
068: }
069:
070: public void testInsertAfter() {
071: area.add(sect);
072: Section newSection = area.insertAfter(null, sect);
073:
074: assertNotSame(newSection, sect);
075: assertEquals(1, area.indexOf(newSection));
076: assertEquals(area.getName(), newSection.getName());
077: assertSame(area, newSection.getArea());
078: }
079:
080: public void testRemove() {
081: area.add(sect);
082: Section newSection = area.insertAfter(null, sect);
083:
084: assertEquals(2, area.size());
085: area.remove(sect);
086: assertNull(sect.getArea());
087: assertEquals(1, area.size());
088: assertSame(newSection, area.first());
089:
090: area.remove(newSection);
091: assertNull(newSection.getArea());
092: assertEquals(0, area.size());
093: }
094:
095: public void testIllegalArg() {
096: try {
097: area.insertAfter(null, null);
098: fail("should have thrown IllegalArgumentException");
099: } 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: } catch (UnsupportedOperationException e) {
118: assertTrue(true);
119: }
120: }
121:
122: public void testClear() {
123: Section sect2 = new Section(report);
124: area.add(sect);
125: area.add(sect2);
126: assertEquals(2, area.size());
127:
128: area.clear();
129: assertEquals(0, area.size());
130:
131: assertNull(sect.getArea());
132: assertNull(sect2.getArea());
133: }
134:
135: public static void main(String[] args) {
136: junit.textui.TestRunner.run(suite());
137: System.exit(0);
138: }
139:
140: }
|