/*******************************************************************************
- * Copyright (c) 2009, 2012 Ericsson
+ * Copyright (c) 2009, 2012, 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* Contributors:
* Francois Chouinard - Initial API and implementation
* Francois Chouinard - Adjusted for new Event Model
+ * Alexandre Montplaisir - Port to JUnit4
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.event;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+import org.junit.Test;
/**
* Test suite for the TmfEventField class.
*/
-@SuppressWarnings("nls")
-public class TmfEventFieldTest extends TestCase {
+@SuppressWarnings({"nls", "javadoc"})
+public class TmfEventFieldTest {
// ------------------------------------------------------------------------
// Variables
private final TmfEventField fRootField = new TmfEventField(fRootFieldName,
new ITmfEventField[] { fField1, fField2 });
- // ------------------------------------------------------------------------
- // Housekeeping
- // ------------------------------------------------------------------------
-
- /**
- * @param name the test name
- */
- public TmfEventFieldTest(final String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testTerminalStructConstructor() {
assertSame("getName", fFieldName1, fStructTerminalField1.getName());
assertNull("getValue", fStructTerminalField1.getValue());
assertNull("getFieldName", fStructTerminalField1.getFieldName(0));
}
- /**
- *
- */
+ @Test
public void testNonTerminalStructConstructor() {
assertSame("getName", fStructRootFieldName, fStructRootField.getName());
assertNull("getValue", fStructRootField.getValue());
assertNull("getFieldName", fStructRootField.getFieldName(names.length));
}
- /**
- *
- */
+ @Test
public void testTerminalConstructor() {
assertSame("getName", fFieldName1, fField1.getName());
assertSame("getValue", fValue1, fField1.getValue());
assertNull("getFieldName", fField2.getFieldName(0));
}
- /**
- *
- */
+ @Test
public void testNonTerminalConstructor() {
assertSame("getName", fRootFieldName, fRootField.getName());
assertNull("getValue", fRootField.getValue());
assertNull("getFieldName", fRootField.getFieldName(names.length));
}
- /**
- *
- */
+ @Test
public void testConstructorBadArg() {
try {
new TmfEventField(null, fValue1, null);
}
}
- /**
- *
- */
+ @Test
public void testTerminalCopyConstructor() {
final TmfEventField copy = new TmfEventField(fField1);
assertSame("getName", fFieldName1, copy.getName());
assertNull("getFieldName", copy.getFieldName(0));
}
- /**
- *
- */
+ @Test
public void testNonTerminalCopyConstructor() {
assertSame("getName", fRootFieldName, fRootField.getName());
assertNull("getValue", fRootField.getValue());
assertNull("getFieldName", fRootField.getFieldName(names.length));
}
- /**
- *
- */
+ @Test
public void testCopyConstructorBadArg() {
try {
new TmfEventField(null);
// hashCode
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testHashCode() {
TmfEventField copy = new TmfEventField(fField1);
assertTrue("hashCode", fField1.hashCode() == copy.hashCode());
// equals
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testEqualsReflexivity() {
assertTrue("equals", fField1.equals(fField1));
assertTrue("equals", fField2.equals(fField2));
assertFalse("equals", fStructTerminalField2.equals(fStructTerminalField1));
}
- /**
- *
- */
+ @Test
public void testEqualsSymmetry() {
final TmfEventField copy0 = new TmfEventField(fField1);
assertTrue("equals", fField1.equals(copy0));
assertTrue("equals", copy3.equals(fField2));
}
- /**
- *
- */
+ @Test
public void testEqualsTransivity() {
TmfEventField copy1 = new TmfEventField(fField1);
TmfEventField copy2 = new TmfEventField(copy1);
assertTrue("equals", fField2.equals(copy2));
}
- /**
- *
- */
+ @Test
public void testEquals() {
assertTrue("equals", fStructTerminalField1.equals(fStructTerminalField3));
assertTrue("equals", fStructTerminalField3.equals(fStructTerminalField1));
assertFalse("equals", fField3.equals(fStructTerminalField1));
}
- /**
- *
- */
+ @Test
public void testEqualsNull() {
assertFalse("equals", fField1.equals(null));
assertFalse("equals", fField2.equals(null));
}
- /**
- *
- */
+ @Test
public void testNonEqualClasses() {
assertFalse("equals", fField1.equals(fStructTerminalField1));
assertFalse("equals", fField1.equals(fValue1));
}
- /**
- *
- */
+ @Test
public void testNonEqualValues() {
final TmfEventField copy1 = new TmfEventField(fFieldName1, fValue1);
TmfEventField copy2 = new TmfEventField(fFieldName1, fValue1);
assertFalse("equals", copy2.equals(copy1));
}
- /**
- *
- */
+ @Test
public void testNonEquals() {
assertFalse("equals", fField1.equals(fField2));
assertFalse("equals", fField2.equals(fField1));
// toString
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testToString() {
final String expected1 = fFieldName1 + "=" + fValue1.toString();
TmfEventField field = new TmfEventField(fFieldName1, fValue1, null);
// makeRoot
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testMakeRoot() {
ITmfEventField root = TmfEventField.makeRoot(fStructFieldNames);
String[] names = root.getFieldNames();