/*******************************************************************************
- * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
-import junit.framework.TestCase;
-
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.junit.Test;
/**
* TmfStatisticsTreeNode Test Cases.
*/
-public class TmfStatisticsTreeNodeTest extends TestCase {
+public class TmfStatisticsTreeNodeTest {
// ------------------------------------------------------------------------
// Fields
// ------------------------------------------------------------------------
- private final String fTypeId1 = "Some type1"; //$NON-NLS-1$
- private final String fTypeId2 = "Some type2"; //$NON-NLS-1$
- private final String fTypeId3 = "Some type3"; //$NON-NLS-1$
+ private final String fTypeId1 = "Some type1";
+ private final String fTypeId2 = "Some type2";
+ private final String fTypeId3 = "Some type3";
private final TmfStatisticsTree fStatsTree;
- private String fTestName = null;
+ private static final String fTestName = "StatisticsTreeNodeTest";
// ------------------------------------------------------------------------
// Housekeeping
// ------------------------------------------------------------------------
/**
- * @param name
- * Test name
+ * Constructor
*/
- public TmfStatisticsTreeNodeTest(final String name) {
- super(name);
-
- fTestName = name;
+ public TmfStatisticsTreeNodeTest() {
fStatsTree = new TmfStatisticsTree();
/* Enter some global values */
fStatsTree.setTypeCount(fTestName, fTypeId3, false, 4);
}
- // ------------------------------------------------------------------------
- // ContainsChild
- // ------------------------------------------------------------------------
-
/**
* Test checking for child.
*/
+ @Test
public void testContainsChild() {
TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
assertFalse(catNode.containsChild(null));
}
- // ------------------------------------------------------------------------
- // GetChildren
- // ------------------------------------------------------------------------
-
/**
* Test getting of children.
*/
+ @Test
public void testGetChildren() {
// Getting children of the ROOT
Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsTree.getRootNode().getChildren();
assertEquals(0, childrenTreeNode.size());
}
- // ------------------------------------------------------------------------
- // GetNbChildren
- // ------------------------------------------------------------------------
-
/**
* Test getting of number of children.
*/
+ @Test
public void testGetNbChildren() {
TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
assertEquals(0, elementNode.getNbChildren());
}
- // ------------------------------------------------------------------------
- // HasChildren
- // ------------------------------------------------------------------------
-
/**
* Test checking for children.
*/
+ @Test
public void testHasChildren() {
TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
assertFalse(elementNode.hasChildren());
}
- // ------------------------------------------------------------------------
- // GetParent
- // ------------------------------------------------------------------------
-
/**
* Test getting of parent.
*/
+ @Test
public void testGetParent() {
final TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
TmfStatisticsTreeNode parentNode = rootNode.getParent();
assertNull(parentNode);
- TmfStatisticsTreeNode newTraceNode = new TmfStatisticsTreeNode(fStatsTree, rootNode, "newly created trace node"); //$NON-NLS-1$
+ TmfStatisticsTreeNode newTraceNode = new TmfStatisticsTreeNode(fStatsTree, rootNode, "newly created trace node");
parentNode = newTraceNode.getParent();
assertNotNull(parentNode);
assertTrue(fStatsTree.getRootNode() == parentNode);
assertTrue(arraysEqual(parentNode.getPath(), fTestName, Messages.TmfStatisticsData_EventTypes));
}
- // ------------------------------------------------------------------------
- // GetKey
- // ------------------------------------------------------------------------
-
/**
* Test getting of key.
*/
+ @Test
public void testgetName() {
TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
TmfStatisticsTreeNode elementNode = fStatsTree.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1);
- assertEquals(0, rootNode.getName().compareTo("root")); //$NON-NLS-1$
+ assertEquals(0, rootNode.getName().compareTo("root"));
assertEquals(0, traceNode.getName().compareTo(fTestName));
assertEquals(0, catNode.getName().compareTo(Messages.TmfStatisticsData_EventTypes));
assertEquals(0, elementNode.getName().compareTo(fTypeId1));
}
- // ------------------------------------------------------------------------
- // GetPath
- // ------------------------------------------------------------------------
-
/**
* Test getting of path to node.
*/
+ @Test
public void testGetPath() {
TmfStatisticsTreeNode rootNode = fStatsTree.getRootNode();
TmfStatisticsTreeNode traceNode = fStatsTree.getNode(fTestName);
fTestName, Messages.TmfStatisticsData_EventTypes, fTypeId1));
}
- // ------------------------------------------------------------------------
- // GetValue
- // ------------------------------------------------------------------------
-
/**
* Test getting statistic value.
*/
+ @Test
public void testGetValue() {
TmfStatisticsTreeNode rootNode, traceNode, catNode, elementNode1, elementNode2, elementNode3;
rootNode = fStatsTree.getRootNode();
assertEquals(4, elementNode3.getValues().getPartial());
}
- // ------------------------------------------------------------------------
- // Reset
- // ------------------------------------------------------------------------
-
/**
* Test reset of tree.
*/
+ @Test
public void testReset() {
TmfStatisticsTreeNode rootNode, traceNode, catNode, elementNode;
rootNode = fStatsTree.getRootNode();
* Test reset global value of the node in the tree. It should only clear
* the global value without removing any node from the tree.
*/
+ @Test
public void testResetGlobalValue() {
TmfStatisticsTreeNode rootNode, traceNode, catNode, eventTypeNode1, eventTypeNode2, eventTypeNode3;
rootNode = fStatsTree.getRootNode();
* Test reset time range value of the node in the tree. It should only clear
* the time range value without removing any node from the tree.
*/
+ @Test
public void testResetTimeRangeValue() {
TmfStatisticsTreeNode rootNode, traceNode, catNode, eventTypeNode1, eventTypeNode2, eventTypeNode3;
rootNode = fStatsTree.getRootNode();