import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.junit.Test;
assertFalse("equals", fField1.equals(fStructTerminalField1));
}
+ /**
+ * Test with same fields, but different values (should not be equal)
+ */
+ @Test
+ public void testNonEqualsValue() {
+ final String fieldName = "myfield";
+ final Object value1 = new String("test-string");
+ final Object value2 = new TmfEvent();
+ final TmfEventField[] fields = { fField1, fField2 };
+
+ final TmfEventField field1 = new TmfEventField(fieldName, value1, fields);
+ final TmfEventField field2 = new TmfEventField(fieldName, value2, fields);
+
+ assertNotEquals(field1, field2);
+ assertNotEquals(field2, field1);
+ }
+
+ /**
+ * Test with same value, but different fields (should not be equal)
+ */
+ @Test
+ public void testNonEqualsFields() {
+ final String fieldName = "myfield";
+ final Object value = new String("test-string");
+ final TmfEventField[] fields1 = { fField1, fField2 };
+ final TmfEventField[] fields2 = { fField2, fField3 };
+
+ final TmfEventField field1 = new TmfEventField(fieldName, value, fields1);
+ final TmfEventField field2 = new TmfEventField(fieldName, value, fields2);
+
+ assertNotEquals(field1, field2);
+ assertNotEquals(field2, field1);
+ }
+
+ /**
+ * Test with same field and values (should be equals)
+ */
+ @Test
+ public void testEqualsEverything() {
+ final String fieldName = "myfield";
+ final Object value = new String("test-string");
+ final TmfEventField[] fields = { fField1, fField2 };
+
+ final TmfEventField field1 = new TmfEventField(fieldName, value, fields);
+ final TmfEventField field2 = new TmfEventField(fieldName, value, fields);
+
+ assertEquals(field1, field2);
+ assertEquals(field2, field1);
+ }
+
// ------------------------------------------------------------------------
// toString
// ------------------------------------------------------------------------
int result = 1;
result = prime * result + fName.hashCode();
result = prime * result + ((value == null) ? 0 : value.hashCode());
+ result = prime * result + fFields.hashCode();
return result;
}
if (!(obj instanceof TmfEventField)) {
return false;
}
+
final TmfEventField other = (TmfEventField) obj;
+
+ /* Check that 'fName' is the same */
if (!fName.equals(other.fName)) {
return false;
}
+
+ /* Check that 'fValue' is the same */
Object value = this.fValue;
if (value == null) {
if (other.fValue != null) {
} else if (!value.equals(other.fValue)) {
return false;
}
+
+ /* Check that 'fFields' are the same */
+ if (!fFields.equals(other.fFields)) {
+ return false;
+ }
+
return true;
}