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