001: package com.mockrunner.test.connector;
002:
003: import java.util.ArrayList;
004: import java.util.Arrays;
005: import java.util.Iterator;
006: import java.util.List;
007:
008: import junit.framework.TestCase;
009:
010: import com.mockrunner.mock.connector.cci.MockIndexedRecord;
011:
012: public class MockIndexedRecordTest extends TestCase {
013: private MockIndexedRecord indexedRecord;
014:
015: protected void setUp() throws Exception {
016: indexedRecord = new MockIndexedRecord();
017: }
018:
019: protected void tearDown() throws Exception {
020: indexedRecord = null;
021: }
022:
023: public void testListOperations() {
024: assertTrue(indexedRecord.isEmpty());
025: assertEquals(0, indexedRecord.size());
026: indexedRecord.add("1");
027: assertFalse(indexedRecord.isEmpty());
028: assertEquals(1, indexedRecord.size());
029: indexedRecord.add("2");
030: Iterator iterator = indexedRecord.iterator();
031: assertEquals("1", iterator.next());
032: assertEquals("2", iterator.next());
033: assertFalse(iterator.hasNext());
034: assertEquals(1, indexedRecord.indexOf("2"));
035: indexedRecord.set(0, "5");
036: String[] array = (String[]) indexedRecord
037: .toArray(new String[indexedRecord.size()]);
038: assertTrue(Arrays.equals(array, new String[] { "5", "2" }));
039: try {
040: indexedRecord.add(5, "5");
041: fail();
042: } catch (IndexOutOfBoundsException exc) {
043: //should throw exception
044: }
045: indexedRecord.remove(1);
046: assertEquals(1, indexedRecord.size());
047: assertEquals("5", indexedRecord.get(0));
048: indexedRecord.remove("7");
049: assertEquals(1, indexedRecord.size());
050: indexedRecord.clear();
051: assertTrue(indexedRecord.isEmpty());
052: assertEquals(0, indexedRecord.size());
053: }
054:
055: public void testEquals() {
056: assertFalse(indexedRecord.equals(null));
057: assertFalse(indexedRecord.equals("abc"));
058: assertTrue(indexedRecord.equals(indexedRecord));
059: indexedRecord.setRecordName("1");
060: indexedRecord.setRecordShortDescription("2");
061: indexedRecord.add("3");
062: MockIndexedRecord other = new MockIndexedRecord();
063: assertFalse(indexedRecord.equals(other));
064: other.add("3");
065: assertFalse(indexedRecord.equals(other));
066: other.setRecordName("1");
067: assertFalse(indexedRecord.equals(other));
068: other.setRecordShortDescription("2");
069: assertTrue(indexedRecord.equals(other));
070: assertTrue(other.equals(indexedRecord));
071: assertEquals(other.hashCode(), indexedRecord.hashCode());
072: other.add(null);
073: assertFalse(indexedRecord.equals(other));
074: assertFalse(other.equals(indexedRecord));
075: indexedRecord.add(null);
076: assertTrue(indexedRecord.equals(other));
077: assertTrue(other.equals(indexedRecord));
078: assertEquals(other.hashCode(), indexedRecord.hashCode());
079: }
080:
081: public void testToString() {
082: indexedRecord.setRecordName("recordName");
083: indexedRecord.setRecordShortDescription("shortDescription");
084: List list = new ArrayList();
085: list.add("1");
086: list.add("2");
087: indexedRecord.addAll(list);
088: String string = indexedRecord.toString();
089: assertTrue(-1 != string.indexOf(MockIndexedRecord.class
090: .getName()));
091: assertTrue(-1 != string.indexOf("recordName"));
092: assertTrue(-1 != string.indexOf("shortDescription"));
093: assertTrue(-1 != string.indexOf(list.toString()));
094: }
095:
096: public void testClone() {
097: indexedRecord.setRecordName("1");
098: indexedRecord.setRecordShortDescription("2");
099: indexedRecord.add("This");
100: indexedRecord.add("is");
101: indexedRecord.add("a");
102: indexedRecord.add("record");
103: MockIndexedRecord clone = (MockIndexedRecord) indexedRecord
104: .clone();
105: assertNotSame(clone, indexedRecord);
106: assertEquals("1", clone.getRecordName());
107: assertEquals("2", clone.getRecordShortDescription());
108: assertEquals("This", clone.get(0));
109: assertEquals("is", clone.get(1));
110: assertEquals("a", clone.get(2));
111: assertEquals("record", clone.get(3));
112: }
113: }
|