[Bug309042] Improved test code coverage and other mundane issues.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / src / org / eclipse / linuxtools / tmf / tests / event / TmfEventFieldTest.java
index f2d5362eaafb53c4ecc1edf1a1a3f50d014747a6..2d3f8c1b367e458061d0f9d0542275faf5e0f687 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.linuxtools.tmf.tests.event;
 
+import junit.framework.TestCase;
+
 import org.eclipse.linuxtools.tmf.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.event.TmfEventContent;
 import org.eclipse.linuxtools.tmf.event.TmfEventField;
@@ -21,24 +23,34 @@ import org.eclipse.linuxtools.tmf.event.TmfEventType;
 import org.eclipse.linuxtools.tmf.event.TmfEventTypeStub;
 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
 
-import junit.framework.TestCase;
-
 /**
  * <b><u>TmfEventFieldTest</u></b>
  * <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfEventField class.
  */
 public class TmfEventFieldTest extends TestCase {
 
+       // ------------------------------------------------------------------------
+       // Variables
+       // ------------------------------------------------------------------------
+
        private final TmfEventContent fContent;
        private final String fFieldId = "Field";
        private final Object fValue1  = new String("Value"); 
        private final Object fValue2  = new Integer(10); 
 
-       // ========================================================================
+       private TmfEventField fField0;
+       private TmfEventField fField1;
+       private TmfEventField fField2;
+       private TmfEventField fField3;
+
+    // ------------------------------------------------------------------------
        // Housekeeping
-       // ========================================================================
+    // ------------------------------------------------------------------------
 
+       /**
+        * @param name the test name
+        */
        public TmfEventFieldTest(String name) {
                super(name);
                TmfTimestamp      fTimestamp   = new TmfTimestamp();
@@ -48,6 +60,11 @@ public class TmfEventFieldTest extends TestCase {
                TmfEvent          fEvent       = new TmfEvent(fTimestamp, fEventSource, fEventType, fReference);
 
                fContent = new TmfEventContent(fEvent, "Some content");
+
+               fField0 = new TmfEventField(fContent, fFieldId, fValue1);
+               fField1 = new TmfEventField(fContent, fFieldId, fValue1);
+               fField2 = new TmfEventField(fContent, fFieldId, fValue1);
+               fField3 = new TmfEventField(fContent, fFieldId, fValue2);
        }
 
        @Override
@@ -60,15 +77,24 @@ public class TmfEventFieldTest extends TestCase {
                super.tearDown();
        }
 
-       // ========================================================================
+    // ------------------------------------------------------------------------
        // Constructors
-       // ========================================================================
+    // ------------------------------------------------------------------------
 
        public void testTmfEventField() {
-               TmfEventField field = new TmfEventField(fContent, fFieldId, fValue1);
-               assertSame("getParent", fContent, field.getParent());
-               assertSame("getId",     fFieldId, field.getId());
-               assertSame("getValue",  fValue1,  field.getValue());
+               assertSame("getParent", fContent, fField0.getParent());
+               assertSame("getId",     fFieldId, fField0.getId());
+               assertSame("getValue",  fValue1,  fField0.getValue());
+       }
+
+       public void testTmfEventFieldBadArg() {
+               try {
+                       new TmfEventField(fContent, null, fValue1);
+                       fail("null copy");
+               }
+               catch (IllegalArgumentException e) {
+                       // Success
+               }
        }
 
        public void testTmfEventFieldCopy() {
@@ -79,28 +105,86 @@ public class TmfEventFieldTest extends TestCase {
                assertSame("getValue",  fValue1,  field.getValue());
        }
 
-       public void testCloneShallowCopy() {
+       public void testTmfEventFieldCopy2() {
+               try {
+                       new TmfEventField(null);
+                       fail("null copy");
+               }
+               catch (IllegalArgumentException e) {
+                       // Success
+               }
+       }
+
+    // ------------------------------------------------------------------------
+       // Modifiers
+    // ------------------------------------------------------------------------
+
+       private class MyField extends TmfEventField {
+               public MyField(TmfEventContent parent, String id, Object value) {
+                       super(parent, id, value);
+               }
+           public MyField(TmfEventField field) {
+                       super(field);
+               }
+               @Override
+               public void setValue(Object value) {
+               super.setValue(value);
+           }
+       }
+
+       public void testSetValue() {
                TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1);
-               TmfEventField field = original.clone();
-               assertSame("getParent", fContent, field.getParent());
-               assertSame("getId",     fFieldId, field.getId());
-               assertSame("getValue",  fValue1,  field.getValue());
+               TmfEventField field = new TmfEventField(original);
+
+               MyField myField = new MyField(field);
+               assertSame("getValue", fValue1,  myField.getValue());
+
+               myField.setValue(fValue2);
+               assertSame("getValue", fValue2,  myField.getValue());
+       }
+
+    // ------------------------------------------------------------------------
+       // equals
+    // ------------------------------------------------------------------------
+
+       public void testEqualsReflexivity() throws Exception {
+               assertTrue("equals", fField0.equals(fField0));
+               assertTrue("equals", fField3.equals(fField3));
+
+               assertTrue("equals", !fField0.equals(fField3));
+               assertTrue("equals", !fField3.equals(fField0));
+       }
+       
+       public void testEqualsSymmetry() throws Exception {
+               assertTrue("equals", fField0.equals(fField1));
+               assertTrue("equals", fField1.equals(fField0));
+
+               assertTrue("equals", !fField0.equals(fField3));
+               assertTrue("equals", !fField3.equals(fField0));
+       }
+       
+       public void testEqualsTransivity() throws Exception {
+               assertTrue("equals", fField0.equals(fField1));
+               assertTrue("equals", fField1.equals(fField2));
+               assertTrue("equals", fField0.equals(fField2));
        }
+       
+       public void testEqualsConsistency() throws Exception {
+               assertTrue("equals", fField0.equals(fField0));
+               assertTrue("equals", fField0.equals(fField0));
 
-//     public void testCloneDeepCopy() {
-//             TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1);
-//             TmfEventField field = original.clone();
-//             assertNotSame("getParent", fContent, field.getParent());
-//             assertNotSame("getId",     fFieldId, field.getId());
-//             assertNotSame("getValue",  fValue1,  field.getValue());
-//             assertEquals ("getParent", fContent, field.getParent());
-//             assertEquals ("getId",     fFieldId, field.getId());
-//             assertEquals ("getValue",  fValue1,  field.getValue());
-//     }
-
-       // ========================================================================
-       // Operators
-       // ========================================================================
+               assertTrue("equals", fField3.equals(fField3));
+               assertTrue("equals", fField3.equals(fField3));
+       }
+       
+       public void testEqualsNull() throws Exception {
+               assertTrue("equals", !fField0.equals(null));
+               assertTrue("equals", !fField3.equals(null));
+       }
+       
+    // ------------------------------------------------------------------------
+       // toString
+    // ------------------------------------------------------------------------
 
        public void testToString() {
                String expected1 = "[TmfEventField(" + fFieldId + ":" + fValue1.toString() + ")]";
This page took 0.026501 seconds and 5 git commands to generate.