/*******************************************************************************
- * Copyright (c) 2011 Ericsson
+ * Copyright (c) 2011, 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:
* Mathieu Denis <mathieu.denis@polymtl.ca> - Initial design and implementation
* Bernd Hufmann - Fixed warnings
+ * Alexandre Montplaisir - Port to JUnit4
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.tests.statistics;
-import java.util.Arrays;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import java.util.Arrays;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
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.eclipse.linuxtools.tmf.core.event.TmfEventType;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfTreeContentProvider;
+import org.junit.Test;
/**
* TmfTreeContentProvider Test Cases.
*/
-@SuppressWarnings("nls")
-public class TmfTreeContentProviderTest extends TestCase {
+public class TmfTreeContentProviderTest {
// ------------------------------------------------------------------------
// Fields
// ------------------------------------------------------------------------
- private String fTestName = null;
+ private static final String fTestName = "TreeContentProviderTest";
private final String fContext = "UnitTest";
private final String fTypeId1 = "Some type1";
private final String fReference = "Some reference";
- private final TmfEvent fEvent1;
- private final TmfEvent fEvent2;
+ private final ITmfEvent fEvent1;
+ private final ITmfEvent fEvent2;
private final TmfEventField fContent1;
private final TmfEventField fContent2;
// ------------------------------------------------------------------------
/**
- * @param name
- * of the test
+ * Constructor
*/
- public TmfTreeContentProviderTest(final String name) {
- super(name);
-
- fTestName = name;
-
+ public TmfTreeContentProviderTest() {
fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some content");
fEvent1 = new TmfEvent(null, fTimestamp1, fSource, fType1, fContent1, fReference);
}
// ------------------------------------------------------------------------
- // GetChildren
+ // Test methods
// ------------------------------------------------------------------------
/**
* FIXME this test was quickly adapted when we removed the TmfFixedArray,
* but it could be rewritten to be much more simple...
*/
+ @Test
public void testGetChildren() {
- Object[] objectArray = treeProvider.getChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes));
+ Object[] objectArray = treeProvider.getChildren(fStatsData.getOrCreateNode(fTestName, Messages.TmfStatisticsData_EventTypes));
TmfStatisticsTreeNode[] childrenNode = Arrays.asList(objectArray).toArray(new TmfStatisticsTreeNode[0]);
String[][] childrenExpected = new String[][] {
return true;
}
- // ------------------------------------------------------------------------
- // GetParent
- // ------------------------------------------------------------------------
-
/**
* Test getting of parent.
*/
+ @Test
public void testGetParent() {
- TmfStatisticsTreeNode parent = (TmfStatisticsTreeNode) treeProvider.getParent(fStatsData.get(fTestName));
+ TmfStatisticsTreeNode parent = (TmfStatisticsTreeNode) treeProvider.getParent(fStatsData.getNode(fTestName));
assertNotNull("getParent", parent);
- assertTrue("getParent", parent.getPath().equals(TmfStatisticsTree.ROOT));
+ assertTrue("getParent", parent.getPath().equals(fStatsData.getRootNode().getPath()));
}
- // ------------------------------------------------------------------------
- // HasChildren
- // ------------------------------------------------------------------------
/**
* Test checking for children.
*/
+ @Test
public void testHasChildren() {
- Boolean hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(TmfStatisticsTree.ROOT));
+ Boolean hasChildren = treeProvider.hasChildren(fStatsData.getRootNode());
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreateNode(fTestName));
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreateNode(fTestName, Messages.TmfStatisticsData_EventTypes));
assertTrue("hasChildren", hasChildren);
- hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()));
+ hasChildren = treeProvider.hasChildren(fStatsData.getOrCreateNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().getName()));
assertFalse("hasChildren", hasChildren);
}
- // ------------------------------------------------------------------------
- // GetElements
- // ------------------------------------------------------------------------
-
/**
* Test getting of elements.
*/
+ @Test
public void testGetElements() {
- Object[] objectElements = treeProvider.getElements(fStatsData.get(TmfStatisticsTree.ROOT));
+ Object[] objectElements = treeProvider.getElements(fStatsData.getRootNode());
TmfStatisticsTreeNode[] nodeElements = Arrays.asList(objectElements).toArray(new TmfStatisticsTreeNode[0]);
assertEquals("getElements", 1, nodeElements.length);
assertTrue("getElements", nodeElements[0].getPath()[0].equals(fTestName));