You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/11/26 21:15:55 UTC
svn commit: r479418 [40/43] - in
/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common:
javax/swing/ javax/swing/border/ javax/swing/colorchooser/
javax/swing/event/ javax/swing/filechooser/ javax/swing/plaf/
javax/swing/plaf/basic/ j...
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainView_SimpleTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainView_SimpleTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainView_SimpleTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainView_SimpleTest.java Sun Nov 26 12:15:43 2006
@@ -23,7 +23,6 @@
import java.awt.Container;
import java.awt.FontMetrics;
import java.awt.Rectangle;
-
import javax.swing.BasicSwingTestCase;
import javax.swing.JTextArea;
import javax.swing.SwingTestCase;
@@ -36,10 +35,8 @@
* initialization (without actual GUI being created).
*/
public class WrappedPlainView_SimpleTest extends SwingTestCase {
-
public class WrappedPlainViewImpl extends WrappedPlainView {
- public WrappedPlainViewImpl(final Element element,
- final boolean wordWrap) {
+ public WrappedPlainViewImpl(final Element element, final boolean wordWrap) {
super(element, wordWrap);
}
@@ -47,39 +44,40 @@
super(element);
}
+ @Override
public Container getContainer() {
return textArea;
}
- public void preferenceChanged(final View child,
- final boolean width,
- final boolean height) {
+ @Override
+ public void preferenceChanged(final View child, final boolean width,
+ final boolean height) {
preferenceParams = new PreferenceChanged(child, width, height);
super.preferenceChanged(child, width, height);
}
- protected boolean updateChildren(final ElementChange change,
- final DocumentEvent event,
- final ViewFactory factory) {
+ @Override
+ protected boolean updateChildren(final ElementChange change, final DocumentEvent event,
+ final ViewFactory factory) {
factoryUsed = factory;
return super.updateChildren(change, event, factory);
}
}
private static class PreferenceChanged {
- public View child;
+ public View child;
+
public boolean width;
+
public boolean height;
- public PreferenceChanged(final View child,
- final boolean width, final boolean height) {
+ public PreferenceChanged(final View child, final boolean width, final boolean height) {
this.child = child;
this.width = width;
this.height = height;
}
- public void check(final View child,
- final boolean width, final boolean height) {
+ public void check(final View child, final boolean width, final boolean height) {
assertEquals("Children are different", this.child, child);
assertEquals("Width is different", this.width, width);
assertEquals("Height is different", this.height, height);
@@ -87,19 +85,26 @@
}
private PreferenceChanged preferenceParams;
- private ViewFactory factoryUsed;
- private Document doc;
- private Element root;
+ private ViewFactory factoryUsed;
+
+ private Document doc;
+
+ private Element root;
+
private WrappedPlainView view;
- private JTextArea textArea;
- private DocumentEvent docEvent;
- private final int width = 40;
+ private JTextArea textArea;
+
+ private DocumentEvent docEvent;
+
+ private final int width = 40;
+
private final int height = 100;
- private final Rectangle shape = new Rectangle(width, height);
+ private final Rectangle shape = new Rectangle(width, height);
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new PlainDocument();
@@ -107,26 +112,24 @@
public void changedUpdate(final DocumentEvent e) {
docEvent = e;
}
+
public void insertUpdate(final DocumentEvent e) {
docEvent = e;
}
+
public void removeUpdate(final DocumentEvent e) {
docEvent = e;
}
});
- doc.insertString(0,
- "one, two, three, four, five\n" +
- "eins, zwei, drei, vier, funf\n" +
- "uno, dos, tres, cuatro, cinco", null);
+ doc.insertString(0, "one, two, three, four, five\n" + "eins, zwei, drei, vier, funf\n"
+ + "uno, dos, tres, cuatro, cinco", null);
root = doc.getDefaultRootElement();
-
textArea = new JTextArea(doc);
view = new WrappedPlainViewImpl(root);
}
public void testLoadChildren() {
assertEquals(0, view.getViewCount());
-
view.loadChildren(null);
assertEquals(root.getElementCount(), view.getViewCount());
}
@@ -137,15 +140,11 @@
public void testWrappedPlainViewElement() throws BadLocationException {
view = new WrappedPlainViewImpl(root);
assertSame(root, view.getElement());
- assertEquals("Major axis expected to be Y",
- View.Y_AXIS, view.getAxis());
-
+ assertEquals("Major axis expected to be Y", View.Y_AXIS, view.getAxis());
Element line2 = root.getElement(1);
view.setSize(width, height);
final int start = line2.getStartOffset();
- int breakOffset = view.calculateBreakPosition(start,
- line2.getEndOffset());
-
+ int breakOffset = view.calculateBreakPosition(start, line2.getEndOffset());
Container container = view.getContainer();
FontMetrics metrics = container.getFontMetrics(container.getFont());
// Assert: text from start up to breakOffset fits into width, but
@@ -153,30 +152,22 @@
if (isHarmony()) {
// 1.5 considers a symbol fits in available width if
// its half fits. We require it to entirely fit.
- assertTrue(width >= metrics.stringWidth(doc.getText(start,
- breakOffset
- - start)));
- }
- assertFalse(width >= metrics.stringWidth(doc.getText(start,
- breakOffset
- - start + 1)));
+ assertTrue(width >= metrics.stringWidth(doc.getText(start, breakOffset - start)));
+ }
+ assertFalse(width >= metrics.stringWidth(doc.getText(start, breakOffset - start + 1)));
}
/*
* Class under test for void WrappedPlainView(Element, boolean)
*/
- public void testWrappedPlainViewElementboolean()
- throws BadLocationException {
-
+ public void testWrappedPlainViewElementboolean() throws BadLocationException {
view = new WrappedPlainViewImpl(root, true);
assertSame(root, view.getElement());
- assertEquals("Major axis expected to be Y",
- View.Y_AXIS, view.getAxis());
-
+ assertEquals("Major axis expected to be Y", View.Y_AXIS, view.getAxis());
Element line2 = root.getElement(1);
view.setSize(width, height);
- int breakOffset = view.calculateBreakPosition(line2.getStartOffset(),
- line2.getEndOffset());
+ int breakOffset = view.calculateBreakPosition(line2.getStartOffset(), line2
+ .getEndOffset());
assertEquals(34, breakOffset);
assertEquals(" zw", doc.getText(breakOffset - 1, 3));
}
@@ -191,7 +182,6 @@
assertEquals(tabPos, view.nextTabStop(10.0f, 0), 0.00001f);
assertEquals(tabPos, view.nextTabStop(tabPos - 1, 0), 0.00001f);
assertEquals(tabPos * 2, view.nextTabStop(tabPos, 0), 0.00001f);
-
// Setting tab size to 4 has no effect on already initialized view
doc.putProperty(PlainDocument.tabSizeAttribute, new Integer(4));
assertEquals(4, view.getTabSize());
@@ -201,9 +191,7 @@
public void testGetTabSize() {
assertEquals(8, view.getTabSize());
-
doc.putProperty(PlainDocument.tabSizeAttribute, new Integer(4));
-
assertEquals(4, view.getTabSize());
}
@@ -211,7 +199,6 @@
Segment buffer = view.getLineBuffer();
assertNotNull(buffer);
assertSame(buffer, view.getLineBuffer());
-
assertNotSame(buffer, new WrappedPlainView(root).getLineBuffer());
}
@@ -221,26 +208,22 @@
public void testCalculateBreakPosition01() throws BadLocationException {
Container container = view.getContainer();
FontMetrics metrics = container.getFontMetrics(container.getFont());
-
Element line = root.getElement(0);
int start = line.getStartOffset();
- int end = line.getEndOffset();
+ int end = line.getEndOffset();
int width = metrics.stringWidth(doc.getText(0, 7))
- - metrics.stringWidth(doc.getText(6, 1)) / 2 - 1;
+ - metrics.stringWidth(doc.getText(6, 1)) / 2 - 1;
view.setSize(width, height);
assertEquals(6, view.calculateBreakPosition(start, end));
assertFalse(" ".equals(doc.getText(5, 1)));
-
if (!isHarmony()) {
// The next assertion may fail on 1.5 as it considers a symbol
// fits on the line if only half of it fits.
return;
}
-
start = 6;
int index = start + 1;
- while (width > metrics.stringWidth(doc.getText(start, index - start))
- && index <= end) {
+ while (width > metrics.stringWidth(doc.getText(start, index - start)) && index <= end) {
++index;
}
if (index < end) {
@@ -259,20 +242,17 @@
view = new WrappedPlainViewImpl(root, true);
Container container = view.getContainer();
FontMetrics metrics = container.getFontMetrics(container.getFont());
-
Element line = root.getElement(0);
int start = line.getStartOffset();
- int end = line.getEndOffset();
+ int end = line.getEndOffset();
int width = metrics.stringWidth(doc.getText(0, 7))
- - metrics.stringWidth(doc.getText(6, 1)) / 2 - 1;
+ - metrics.stringWidth(doc.getText(6, 1)) / 2 - 1;
view.setSize(width, height);
assertEquals(5, view.calculateBreakPosition(start, end));
assertTrue(" ".equals(doc.getText(4, 1)));
-
start = 6;
int index = start + 1;
- while (width > metrics.stringWidth(doc.getText(start, index - start))
- && index <= end) {
+ while (width > metrics.stringWidth(doc.getText(start, index - start)) && index <= end) {
++index;
}
if (index < end) {
@@ -280,7 +260,6 @@
do {
--index;
} while (!" ".equals(doc.getText(index, 1)));
-
assertEquals(index + 1, view.calculateBreakPosition(start, end));
assertTrue(" ".equals(doc.getText(index, 1)));
} else {
@@ -294,22 +273,18 @@
*/
public void testCalculateBreakPosition03() throws BadLocationException {
String veryLongString = "aVeryVeryVeryLongString";
- doc.insertString(root.getElement(1).getStartOffset(),
- veryLongString, null);
+ doc.insertString(root.getElement(1).getStartOffset(), veryLongString, null);
Container container = view.getContainer();
FontMetrics metrics = container.getFontMetrics(container.getFont());
-
Element line = root.getElement(1);
int start = line.getStartOffset();
- int end = line.getEndOffset();
+ int end = line.getEndOffset();
int width = metrics.stringWidth(veryLongString) / 2;
view.setSize(width, height);
int breakPos = view.calculateBreakPosition(start, end);
-
// Create a new view with word wrapping
view = new WrappedPlainViewImpl(root, true);
view.setSize(width, height);
-
assertEquals(breakPos, view.calculateBreakPosition(start, end));
assertFalse(" ".equals(doc.getText(breakPos - 1, 1)));
}
@@ -320,9 +295,8 @@
if (BasicSwingTestCase.isHarmony()) {
assertNotNull(factoryUsed);
assertSame(factoryUsed, view.viewFactory);
-
- assertEquals("javax.swing.text.WrappedPlainView$LineView",
- factoryUsed.create(root).getClass().getName());
+ assertEquals("javax.swing.text.WrappedPlainView$LineView", factoryUsed.create(root)
+ .getClass().getName());
}
}
@@ -347,12 +321,9 @@
public void testSetSize() {
assertFalse(view.isLayoutValid(View.X_AXIS));
assertFalse(view.isLayoutValid(View.Y_AXIS));
-
view.setSize(width, height);
-
assertTrue(view.isLayoutValid(View.X_AXIS));
assertTrue(view.isLayoutValid(View.Y_AXIS));
-
assertNotNull(preferenceParams);
preferenceParams.check(null, true, true);
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/tree/AbstractLayoutCacheTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/tree/AbstractLayoutCacheTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/tree/AbstractLayoutCacheTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/tree/AbstractLayoutCacheTest.java Sun Nov 26 12:15:43 2006
@@ -15,21 +15,19 @@
* limitations under the License.
*/
/**
-* @author Alexander T. Simbirtsev
-* @version $Revision$
-*/
+ * @author Alexander T. Simbirtsev
+ * @version $Revision$
+ */
package javax.swing.tree;
import java.awt.Rectangle;
import java.util.Enumeration;
-
import javax.swing.JTree;
import javax.swing.SwingTestCase;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
public class AbstractLayoutCacheTest extends SwingTestCase {
-
protected class UndefaultTreeModel implements TreeModel {
private Object root;
@@ -38,26 +36,24 @@
}
public Object getChild(Object parent, int i) {
- return ((TreeNode)parent).getChildAt(i);
+ return ((TreeNode) parent).getChildAt(i);
}
public int getChildCount(Object node) {
- return ((TreeNode)node).getChildCount();
+ return ((TreeNode) node).getChildCount();
}
public int getIndexOfChild(Object parent, Object child) {
if (parent == null || child == null) {
return -1;
}
-
- TreeNode parentNode = (TreeNode)parent;
+ TreeNode parentNode = (TreeNode) parent;
int numChildren = parentNode.getChildCount();
for (int i = 0; i < numChildren; i++) {
if (child.equals(parentNode.getChildAt(i))) {
return i;
}
}
-
return -1;
}
@@ -71,33 +67,37 @@
public void valueForPathChanged(TreePath path, Object value) {
}
+
public void addTreeModelListener(TreeModelListener l) {
}
+
public void removeTreeModelListener(TreeModelListener l) {
}
};
protected class ConcreteLayoutCache extends AbstractLayoutCache {
public class FakeNodeDimensions extends AbstractLayoutCache.NodeDimensions {
+ @Override
public Rectangle getNodeDimensions(final Object value, final int row,
- final int depth, final boolean expanded,
- final Rectangle placeIn) {
+ final int depth, final boolean expanded, final Rectangle placeIn) {
return new Rectangle(value.hashCode(), row, depth, expanded ? 1 : 0);
}
};
+
public class NearlyFakeNodeDimensions extends AbstractLayoutCache.NodeDimensions {
+ @Override
public Rectangle getNodeDimensions(final Object value, final int row,
- final int depth, final boolean expanded,
- final Rectangle placeIn) {
- return new Rectangle(10000*depth, 100*row, 10*(Math.abs(row) + 1), 1000*(Math.abs(row) + 1));
+ final int depth, final boolean expanded, final Rectangle placeIn) {
+ return new Rectangle(10000 * depth, 100 * row, 10 * (Math.abs(row) + 1),
+ 1000 * (Math.abs(row) + 1));
}
};
public class RealisticNodeDimensions extends AbstractLayoutCache.NodeDimensions {
+ @Override
public Rectangle getNodeDimensions(final Object value, final int row,
- final int depth, final boolean expanded,
- final Rectangle placeIn) {
- return new Rectangle(depth*10, row*10, 100, 10);
+ final int depth, final boolean expanded, final Rectangle placeIn) {
+ return new Rectangle(depth * 10, row * 10, 100, 10);
}
};
@@ -107,109 +107,143 @@
} else if (type == 1) {
return new NearlyFakeNodeDimensions();
}
-
return new RealisticNodeDimensions();
}
+ @Override
public Rectangle getBounds(TreePath path, Rectangle palceIn) {
return null;
}
+ @Override
public boolean getExpandedState(TreePath path) {
return false;
}
+ @Override
public TreePath getPathClosestTo(int x, int y) {
return null;
}
+ @Override
public TreePath getPathForRow(int row) {
return null;
}
+ @Override
public int getRowCount() {
return 0;
}
+ @Override
public int getRowForPath(TreePath path) {
return 111;
}
+ @Override
public int getVisibleChildCount(TreePath path) {
return 0;
}
+ @SuppressWarnings("unchecked")
+ @Override
public Enumeration getVisiblePathsFrom(TreePath path) {
return null;
}
+ @Override
public void invalidatePathBounds(TreePath path) {
}
+ @Override
public void invalidateSizes() {
}
+ @Override
public boolean isExpanded(TreePath path) {
return false;
}
+ @Override
public void setExpandedState(TreePath path, boolean expanded) {
}
+ @Override
public void treeNodesChanged(TreeModelEvent e) {
}
+ @Override
public void treeNodesInserted(TreeModelEvent e) {
}
+ @Override
public void treeNodesRemoved(TreeModelEvent e) {
}
+ @Override
public void treeStructureChanged(TreeModelEvent e) {
}
};
protected final DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
+
protected final DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("node1");
+
protected final DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("node2");
+
protected final DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("node3");
+
protected final DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("node4");
+
protected final DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("node5");
+
protected final DefaultMutableTreeNode node6 = new DefaultMutableTreeNode("node6");
protected final TreePath rootPath = new TreePath(root);
- protected final TreePath path1 = new TreePath(new Object[] {root, node1});
- protected final TreePath path2 = new TreePath(new Object[] {root, node2});
- protected final TreePath path3 = new TreePath(new Object[] {root, node3});
- protected final TreePath path4 = new TreePath(new Object[] {root, node4});
- protected final TreePath path23 = new TreePath(new Object[] {root, node2, node3});
- protected final TreePath path24 = new TreePath(new Object[] {root, node2, node4});
- protected final TreePath path234 = new TreePath(new Object[] {root, node2, node3, node4});
- protected final TreePath path13 = new TreePath(new Object[] {root, node1, node3});
- protected final TreePath path14 = new TreePath(new Object[] {root, node1, node4});
- protected final TreePath path25 = new TreePath(new Object[] {root, node2, node5});
- protected final TreePath path26 = new TreePath(new Object[] {root, node2, node6});
+
+ protected final TreePath path1 = new TreePath(new Object[] { root, node1 });
+
+ protected final TreePath path2 = new TreePath(new Object[] { root, node2 });
+
+ protected final TreePath path3 = new TreePath(new Object[] { root, node3 });
+
+ protected final TreePath path4 = new TreePath(new Object[] { root, node4 });
+
+ protected final TreePath path23 = new TreePath(new Object[] { root, node2, node3 });
+
+ protected final TreePath path24 = new TreePath(new Object[] { root, node2, node4 });
+
+ protected final TreePath path234 = new TreePath(new Object[] { root, node2, node3, node4 });
+
+ protected final TreePath path13 = new TreePath(new Object[] { root, node1, node3 });
+
+ protected final TreePath path14 = new TreePath(new Object[] { root, node1, node4 });
+
+ protected final TreePath path25 = new TreePath(new Object[] { root, node2, node5 });
+
+ protected final TreePath path26 = new TreePath(new Object[] { root, node2, node6 });
protected AbstractLayoutCache.NodeDimensions dimensions1;
+
protected AbstractLayoutCache.NodeDimensions dimensions2;
+
protected AbstractLayoutCache.NodeDimensions dimensions3;
protected int defaultRowValue;
protected AbstractLayoutCache cache;
+ @Override
protected void setUp() throws Exception {
super.setUp();
-
cache = new ConcreteLayoutCache();
-
- dimensions1 = ((ConcreteLayoutCache)cache).createNodeDimensions(0);
- dimensions2 = ((ConcreteLayoutCache)cache).createNodeDimensions(2);
- dimensions3 = ((ConcreteLayoutCache)cache).createNodeDimensions(1);
-
+ dimensions1 = ((ConcreteLayoutCache) cache).createNodeDimensions(0);
+ dimensions2 = ((ConcreteLayoutCache) cache).createNodeDimensions(2);
+ dimensions3 = ((ConcreteLayoutCache) cache).createNodeDimensions(1);
defaultRowValue = cache.getRowForPath(null);
}
+ @Override
protected void tearDown() throws Exception {
cache = null;
root.removeAllChildren();
@@ -219,7 +253,6 @@
node4.removeAllChildren();
node5.removeAllChildren();
node6.removeAllChildren();
-
super.tearDown();
}
@@ -240,7 +273,6 @@
public void testGetModel() {
TreeModel model = new DefaultTreeModel(null);
assertNull(cache.getModel());
-
cache.treeModel = model;
assertEquals(model, cache.getModel());
}
@@ -252,15 +284,12 @@
TreeModel model1 = new DefaultTreeModel(null);
TreeModel model2 = new DefaultTreeModel(root);
assertNull(cache.getModel());
-
cache.setModel(model1);
assertSame(model1, cache.treeModel);
assertSame(model1, cache.getModel());
-
cache.setModel(model2);
assertSame(model2, cache.treeModel);
assertSame(model2, cache.getModel());
-
if (getClass() == AbstractLayoutCacheTest.class) {
return;
}
@@ -270,7 +299,6 @@
node1.add(node4);
node2.add(node5);
node2.add(node6);
-
cache.setRootVisible(true);
cache.setExpandedState(path1, true);
assertEquals(0, cache.getRowForPath(rootPath));
@@ -280,7 +308,6 @@
assertEquals(4, cache.getRowForPath(path2));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
-
cache.setModel(model1);
assertEquals(-1, cache.getRowForPath(rootPath));
assertEquals(-1, cache.getRowForPath(path1));
@@ -297,7 +324,6 @@
public void testGetSelectionModel() {
TreeSelectionModel model = new DefaultTreeSelectionModel();
assertNull(cache.getSelectionModel());
-
cache.treeSelectionModel = model;
assertEquals(model, cache.getSelectionModel());
}
@@ -309,18 +335,15 @@
TreeSelectionModel model1 = new DefaultTreeSelectionModel();
TreeSelectionModel model2 = new DefaultTreeSelectionModel();
assertNull(cache.getSelectionModel());
-
cache.setSelectionModel(model1);
assertSame(cache, model1.getRowMapper());
assertEquals(model1, cache.treeSelectionModel);
assertEquals(model1, cache.getSelectionModel());
-
cache.setSelectionModel(model2);
assertSame(cache, model2.getRowMapper());
assertNull(model1.getRowMapper());
assertEquals(model2, cache.treeSelectionModel);
assertEquals(model2, cache.getSelectionModel());
-
cache.setSelectionModel(null);
assertNull(cache.getSelectionModel());
}
@@ -332,7 +355,6 @@
cache.setRootVisible(true);
assertTrue(cache.rootVisible);
assertTrue(cache.isRootVisible());
-
cache.setRootVisible(false);
assertFalse(cache.rootVisible);
assertFalse(cache.isRootVisible());
@@ -344,7 +366,6 @@
public void testIsRootVisible() {
cache.rootVisible = true;
assertTrue(cache.isRootVisible());
-
cache.rootVisible = false;
assertFalse(cache.isRootVisible());
}
@@ -356,7 +377,6 @@
cache.setRowHeight(100);
assertEquals(100, cache.rowHeight);
assertEquals(100, cache.getRowHeight());
-
cache.setRowHeight(200);
assertEquals(200, cache.rowHeight);
assertEquals(200, cache.getRowHeight());
@@ -368,7 +388,6 @@
public void testGetRowHeight() {
cache.rowHeight = 100;
assertEquals(100, cache.getRowHeight());
-
cache.rowHeight = 200;
assertEquals(200, cache.getRowHeight());
}
@@ -378,11 +397,10 @@
*/
public void testGetNodeDimensionsObjectIntIntBooleanRectangle() {
AbstractLayoutCache.NodeDimensions renderer1 = dimensions1;
-
assertNull(cache.getNodeDimensions(null, 1, 1, true, null));
-
cache.setNodeDimensions(renderer1);
- assertEquals(new Rectangle("a".hashCode(), 10, 20, 1), cache.getNodeDimensions("a", 10, 20, true, null));
+ assertEquals(new Rectangle("a".hashCode(), 10, 20, 1), cache.getNodeDimensions("a", 10,
+ 20, true, null));
}
/*
@@ -391,10 +409,8 @@
public void testGetNodeDimensions() {
AbstractLayoutCache.NodeDimensions renderer1 = dimensions1;
AbstractLayoutCache.NodeDimensions renderer2 = dimensions2;
-
cache.nodeDimensions = renderer1;
assertEquals(renderer1, cache.getNodeDimensions());
-
cache.nodeDimensions = renderer2;
assertEquals(renderer2, cache.getNodeDimensions());
}
@@ -405,11 +421,9 @@
public void testSetNodeDimensions() {
AbstractLayoutCache.NodeDimensions renderer1 = dimensions1;
AbstractLayoutCache.NodeDimensions renderer2 = dimensions2;
-
cache.setNodeDimensions(renderer1);
assertSame(renderer1, cache.nodeDimensions);
assertSame(renderer1, cache.getNodeDimensions());
-
cache.setNodeDimensions(renderer2);
assertSame(renderer2, cache.nodeDimensions);
assertSame(renderer2, cache.getNodeDimensions());
@@ -428,7 +442,6 @@
public void testGetPreferredWidth() {
assertEquals(0, cache.getPreferredWidth(null));
assertEquals(0, cache.getPreferredWidth(new Rectangle(0, 0, 20, 20)));
-
JTree tree = new JTree();
cache.setModel(tree.getModel());
cache.setRootVisible(true);
@@ -448,10 +461,8 @@
assertEquals(0, cache.getRowsForPaths(null).length);
}
assertEquals(0, cache.getRowsForPaths(new TreePath[0]).length);
-
- TreePath[] paths = new TreePath[] {new TreePath("1"),
- new TreePath("2"),
- new TreePath(new Object[] {"1", "2"})};
+ TreePath[] paths = new TreePath[] { new TreePath("1"), new TreePath("2"),
+ new TreePath(new Object[] { "1", "2" }) };
assertEquals(3, cache.getRowsForPaths(paths).length);
assertEquals(defaultRowValue, cache.getRowsForPaths(paths)[0]);
assertEquals(defaultRowValue, cache.getRowsForPaths(paths)[1]);
@@ -463,28 +474,25 @@
*/
public void testIsFixedRowHeight() {
assertFalse(cache.isFixedRowHeight());
-
cache.setRowHeight(1);
assertTrue(cache.isFixedRowHeight());
-
cache.setRowHeight(0);
assertFalse(cache.isFixedRowHeight());
-
cache.setRowHeight(-10);
assertFalse(cache.isFixedRowHeight());
}
+ @SuppressWarnings("unchecked")
protected boolean checkEnumeration(final Enumeration e, final Object[] array) {
int size = (array != null) ? array.length : 0;
boolean enumEmpty = (e == null) || (!e.hasMoreElements());
boolean arrayEmpty = (size == 0);
if (enumEmpty || arrayEmpty) {
-// if (enumEmpty != arrayEmpty) {
-// System.out.println("sizes: " + array.length);
-// }
+ // if (enumEmpty != arrayEmpty) {
+ // System.out.println("sizes: " + array.length);
+ // }
return (enumEmpty == arrayEmpty);
}
-
int i = 0;
while (e.hasMoreElements()) {
Object element = e.nextElement();
@@ -492,7 +500,6 @@
return false;
}
}
-
return (i == size);
}
@@ -503,46 +510,38 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
root.add(node1);
root.add(node2);
node2.add(node3);
node3.add(node4);
-
TreeModel model = new DefaultTreeModel(root);
cache.setModel(model);
-
cache.setExpandedState(rootPath, false);
assertFalse(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
assertFalse(cache.getExpandedState(path2));
assertFalse(cache.getExpandedState(path23));
-
cache.setExpandedState(path1, true);
assertTrue(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
assertFalse(cache.getExpandedState(path2));
assertFalse(cache.getExpandedState(path23));
-
cache.setExpandedState(rootPath, false);
cache.setExpandedState(path2, true);
assertTrue(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
assertTrue(cache.getExpandedState(path2));
assertFalse(cache.getExpandedState(path23));
-
cache.setExpandedState(rootPath, false);
assertFalse(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
assertFalse(cache.getExpandedState(path2));
assertFalse(cache.getExpandedState(path23));
-
cache.setExpandedState(rootPath, true);
assertTrue(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
assertTrue(cache.getExpandedState(path2));
assertFalse(cache.getExpandedState(path23));
-
cache.setExpandedState(rootPath, false);
cache.setExpandedState(path2, false);
cache.setExpandedState(path234, true);
@@ -560,29 +559,23 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
root.add(node1);
root.add(node2);
node2.add(node3);
-
assertFalse(cache.getExpandedState(rootPath));
-
TreeModel model = new DefaultTreeModel(root);
cache.setModel(model);
assertTrue(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
assertFalse(cache.getExpandedState(path2));
-
cache.setExpandedState(path1, true);
assertTrue(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
assertFalse(cache.getExpandedState(path2));
-
cache.setExpandedState(path2, true);
assertTrue(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
assertTrue(cache.getExpandedState(path2));
-
cache.setRootVisible(false);
assertTrue(cache.getExpandedState(rootPath));
assertFalse(cache.getExpandedState(path1));
@@ -596,34 +589,27 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
root.add(node1);
root.add(node2);
node2.add(node3);
-
assertFalse(cache.isExpanded(rootPath));
-
TreeModel model = new DefaultTreeModel(root);
cache.setModel(model);
assertTrue(cache.isExpanded(rootPath));
assertFalse(cache.isExpanded(path1));
assertFalse(cache.isExpanded(path2));
-
cache.setExpandedState(path1, true);
assertTrue(cache.isExpanded(rootPath));
assertFalse(cache.isExpanded(path1));
assertFalse(cache.isExpanded(path2));
-
cache.setExpandedState(path2, true);
assertTrue(cache.isExpanded(rootPath));
assertFalse(cache.isExpanded(path1));
assertTrue(cache.isExpanded(path2));
-
cache.setExpandedState(rootPath, false);
assertFalse(cache.isExpanded(rootPath));
assertFalse(cache.isExpanded(path1));
assertFalse(cache.isExpanded(path2));
-
cache.setExpandedState(path1, true);
assertTrue(cache.isExpanded(rootPath));
assertFalse(cache.isExpanded(path1));
@@ -637,31 +623,26 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
root.add(node1);
root.add(node2);
node1.add(node3);
node1.add(node4);
node2.add(node5);
node2.add(node6);
-
assertNull(cache.getPathForRow(0));
cache.setRootVisible(true);
assertNull(cache.getPathForRow(0));
-
TreeModel model = new UndefaultTreeModel(root);
cache.setModel(model);
cache.setRootVisible(false);
assertEquals(path1, cache.getPathForRow(0));
assertEquals(path2, cache.getPathForRow(1));
assertNull(cache.getPathForRow(2));
-
cache.setRootVisible(true);
assertEquals(rootPath, cache.getPathForRow(0));
assertEquals(path1, cache.getPathForRow(1));
assertEquals(path2, cache.getPathForRow(2));
assertNull(cache.getPathForRow(3));
-
cache.setExpandedState(path1, true);
assertEquals(rootPath, cache.getPathForRow(0));
assertEquals(path1, cache.getPathForRow(1));
@@ -669,7 +650,6 @@
assertEquals(path14, cache.getPathForRow(3));
assertEquals(path2, cache.getPathForRow(4));
assertNull(cache.getPathForRow(5));
-
cache.setExpandedState(path1, false);
cache.setExpandedState(path2, true);
assertEquals(rootPath, cache.getPathForRow(0));
@@ -708,20 +688,16 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
root.add(node1);
root.add(node2);
node1.add(node3);
node1.add(node4);
node2.add(node5);
node2.add(node6);
-
assertEquals(-1, cache.getRowForPath(null));
assertEquals(-1, cache.getRowForPath(rootPath));
-
cache.setRootVisible(true);
assertEquals(-1, cache.getRowForPath(rootPath));
-
TreeModel model = new UndefaultTreeModel(root);
cache.setModel(model);
cache.setRootVisible(false);
@@ -732,7 +708,6 @@
assertEquals(-1, cache.getRowForPath(path14));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
-
cache.setRootVisible(true);
assertEquals(0, cache.getRowForPath(rootPath));
assertEquals(1, cache.getRowForPath(path1));
@@ -741,7 +716,6 @@
assertEquals(-1, cache.getRowForPath(path14));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
-
cache.setExpandedState(path1, true);
assertEquals(0, cache.getRowForPath(rootPath));
assertEquals(1, cache.getRowForPath(path1));
@@ -750,7 +724,6 @@
assertEquals(4, cache.getRowForPath(path2));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
-
cache.setExpandedState(path1, false);
cache.setExpandedState(path2, true);
assertEquals(0, cache.getRowForPath(rootPath));
@@ -769,29 +742,24 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
root.add(node1);
root.add(node2);
node2.add(node3);
node2.add(node4);
-
TreeModel model = new DefaultTreeModel(root);
assertEquals(0, cache.getVisibleChildCount(rootPath));
cache.setModel(model);
assertEquals(2, cache.getVisibleChildCount(rootPath));
assertEquals(0, cache.getVisibleChildCount(path1));
assertEquals(0, cache.getVisibleChildCount(path2));
-
cache.setExpandedState(rootPath, false);
assertEquals(0, cache.getVisibleChildCount(rootPath));
assertEquals(0, cache.getVisibleChildCount(path1));
assertEquals(0, cache.getVisibleChildCount(path2));
-
cache.setExpandedState(path2, true);
assertEquals(4, cache.getVisibleChildCount(rootPath));
assertEquals(0, cache.getVisibleChildCount(path1));
assertEquals(2, cache.getVisibleChildCount(path2));
-
cache.setExpandedState(rootPath, false);
assertEquals(0, cache.getVisibleChildCount(rootPath));
assertEquals(0, cache.getVisibleChildCount(path1));
@@ -805,57 +773,44 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
- final TreePath path5 = new TreePath(new Object[] {root, node5});
-
+ final TreePath path5 = new TreePath(new Object[] { root, node5 });
root.add(node1);
root.add(node2);
node2.add(node3);
node2.add(node4);
root.add(node5);
-
- assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath),
- new Object[] {}));
-
+ assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath), new Object[] {}));
TreeModel model = new DefaultTreeModel(root);
cache.setModel(model);
-
- assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath),
- new Object[] {rootPath, path1, path2, path5}));
- assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path1),
- new Object[] {path1, path2, path5}));
- assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path2),
- new Object[] {path2, path5}));
-
+ assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath), new Object[] {
+ rootPath, path1, path2, path5 }));
+ assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path1), new Object[] { path1,
+ path2, path5 }));
+ assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path2), new Object[] { path2,
+ path5 }));
cache.setExpandedState(rootPath, false);
assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath),
- new Object[] {rootPath}));
-
+ new Object[] { rootPath }));
assertNull(cache.getVisiblePathsFrom(path1));
assertNull(cache.getVisiblePathsFrom(path2));
-
cache.setRootVisible(false);
assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath),
- new Object[] {rootPath}));
+ new Object[] { rootPath }));
assertNull(cache.getVisiblePathsFrom(path1));
assertNull(cache.getVisiblePathsFrom(path2));
-
cache.setRootVisible(true);
-
cache.setExpandedState(path2, true);
- assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath),
- new Object[] {rootPath, path1, path2, path23, path24, path5}));
- assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path1),
- new Object[] {path1, path2, path23, path24, path5}));
- assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path2),
- new Object[] {path2, path23, path24, path5}));
- assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path23),
- new Object[] {path23, path24, path5}));
-
+ assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath), new Object[] {
+ rootPath, path1, path2, path23, path24, path5 }));
+ assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path1), new Object[] { path1,
+ path2, path23, path24, path5 }));
+ assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path2), new Object[] { path2,
+ path23, path24, path5 }));
+ assertTrue(checkEnumeration(cache.getVisiblePathsFrom(path23), new Object[] { path23,
+ path24, path5 }));
cache.setExpandedState(rootPath, false);
assertTrue(checkEnumeration(cache.getVisiblePathsFrom(rootPath),
- new Object[] {rootPath}));
-
+ new Object[] { rootPath }));
assertNull(cache.getVisiblePathsFrom(path1));
assertNull(cache.getVisiblePathsFrom(path2));
}
@@ -873,56 +828,50 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
root.add(node1);
-
TreeModel model = new UndefaultTreeModel(root);
cache.setModel(model);
assertEquals(0, cache.getRowForPath(path1));
assertEquals(-1, cache.getRowForPath(path2));
-
root.insert(node2, 0);
-
- cache.treeNodesInserted(new TreeModelEvent(model, rootPath, new int[] {0}, new Object[] {node2}));
+ cache.treeNodesInserted(new TreeModelEvent(model, rootPath, new int[] { 0 },
+ new Object[] { node2 }));
assertEquals(0, cache.getRowForPath(path2));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
assertEquals(1, cache.getRowForPath(path1));
assertEquals(-1, cache.getRowForPath(path13));
assertEquals(-1, cache.getRowForPath(path14));
-
node2.add(node6);
- cache.treeNodesInserted(new TreeModelEvent(model, path2, new int[] {0}, null));
+ cache.treeNodesInserted(new TreeModelEvent(model, path2, new int[] { 0 }, null));
assertEquals(0, cache.getRowForPath(path2));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
assertEquals(1, cache.getRowForPath(path1));
assertEquals(-1, cache.getRowForPath(path13));
assertEquals(-1, cache.getRowForPath(path14));
-
cache.setExpandedState(path2, true);
node2.insert(node5, 0);
- cache.treeNodesInserted(new TreeModelEvent(model, path2, new int[] {0}, null));
+ cache.treeNodesInserted(new TreeModelEvent(model, path2, new int[] { 0 }, null));
assertEquals(0, cache.getRowForPath(path2));
assertEquals(1, cache.getRowForPath(path25));
assertEquals(2, cache.getRowForPath(path26));
assertEquals(3, cache.getRowForPath(path1));
assertEquals(-1, cache.getRowForPath(path13));
assertEquals(-1, cache.getRowForPath(path14));
-
node1.add(node3);
- cache.treeNodesInserted(new TreeModelEvent(model, path1, new int[] {0}, new Object[] {node3}));
+ cache.treeNodesInserted(new TreeModelEvent(model, path1, new int[] { 0 },
+ new Object[] { node3 }));
assertEquals(0, cache.getRowForPath(path2));
assertEquals(1, cache.getRowForPath(path25));
assertEquals(2, cache.getRowForPath(path26));
assertEquals(3, cache.getRowForPath(path1));
assertEquals(-1, cache.getRowForPath(path13));
assertEquals(-1, cache.getRowForPath(path14));
-
-
cache.setExpandedState(path1, true);
node1.add(node4);
- cache.treeNodesInserted(new TreeModelEvent(model, path1, new int[] {1}, new Object[] {node4}));
+ cache.treeNodesInserted(new TreeModelEvent(model, path1, new int[] { 1 },
+ new Object[] { node4 }));
assertEquals(0, cache.getRowForPath(path2));
assertEquals(1, cache.getRowForPath(path25));
assertEquals(2, cache.getRowForPath(path26));
@@ -938,7 +887,6 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
TreeModel model = new UndefaultTreeModel(root);
root.add(node1);
root.add(node2);
@@ -946,7 +894,6 @@
node1.add(node4);
node2.add(node5);
node2.add(node6);
-
cache.setModel(model);
cache.setExpandedState(path1, true);
cache.setExpandedState(path2, true);
@@ -956,29 +903,29 @@
assertEquals(3, cache.getRowForPath(path2));
assertEquals(4, cache.getRowForPath(path25));
assertEquals(5, cache.getRowForPath(path26));
-
node1.remove(0);
- cache.treeNodesRemoved(new TreeModelEvent(model, path1, new int[] {0}, new Object[] {node1}));
+ cache.treeNodesRemoved(new TreeModelEvent(model, path1, new int[] { 0 },
+ new Object[] { node1 }));
assertEquals(0, cache.getRowForPath(path1));
-// assertEquals(-1, cache.getRowForPath(path13));
+ // assertEquals(-1, cache.getRowForPath(path13));
assertEquals(1, cache.getRowForPath(path14));
assertEquals(2, cache.getRowForPath(path2));
assertEquals(3, cache.getRowForPath(path25));
assertEquals(4, cache.getRowForPath(path26));
assertTrue(cache.getExpandedState(path1));
-
node1.remove(0);
- cache.treeNodesRemoved(new TreeModelEvent(model, path1, new int[] {0}, new Object[] {node4}));
+ cache.treeNodesRemoved(new TreeModelEvent(model, path1, new int[] { 0 },
+ new Object[] { node4 }));
assertEquals(0, cache.getRowForPath(path1));
-// assertEquals(-1, cache.getRowForPath(path13));
-// assertEquals(-1, cache.getRowForPath(path14));
+ // assertEquals(-1, cache.getRowForPath(path13));
+ // assertEquals(-1, cache.getRowForPath(path14));
assertEquals(1, cache.getRowForPath(path2));
assertEquals(2, cache.getRowForPath(path25));
assertEquals(3, cache.getRowForPath(path26));
assertTrue(cache.getExpandedState(path1));
-
root.remove(0);
- cache.treeNodesRemoved(new TreeModelEvent(model, rootPath, new int[] {0}, new Object[] {node1}));
+ cache.treeNodesRemoved(new TreeModelEvent(model, rootPath, new int[] { 0 },
+ new Object[] { node1 }));
assertEquals(-1, cache.getRowForPath(path1));
assertEquals(-1, cache.getRowForPath(path13));
assertEquals(-1, cache.getRowForPath(path14));
@@ -988,9 +935,9 @@
if (isHarmony()) {
assertFalse(cache.getExpandedState(path1));
}
-
root.remove(0);
- cache.treeNodesRemoved(new TreeModelEvent(model, rootPath, new int[] {0}, new Object[] {node2}));
+ cache.treeNodesRemoved(new TreeModelEvent(model, rootPath, new int[] { 0 },
+ new Object[] { node2 }));
if (isHarmony()) {
assertEquals(-1, cache.getRowForPath(path1));
}
@@ -1013,18 +960,15 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
TreeModel model = new UndefaultTreeModel(root);
root.add(node1);
root.add(node2);
node2.add(node5);
-
cache.setModel(model);
assertEquals(0, cache.getRowForPath(path1));
assertEquals(1, cache.getRowForPath(path2));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
-
root.add(node3);
root.add(node4);
cache.treeStructureChanged(new TreeModelEvent(model, path1));
@@ -1032,7 +976,6 @@
assertEquals(1, cache.getRowForPath(path2));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
-
cache.treeStructureChanged(new TreeModelEvent(model, rootPath));
assertEquals(0, cache.getRowForPath(path1));
assertEquals(1, cache.getRowForPath(path2));
@@ -1040,18 +983,15 @@
assertEquals(3, cache.getRowForPath(path4));
assertEquals(-1, cache.getRowForPath(path25));
assertEquals(-1, cache.getRowForPath(path26));
-
cache.setExpandedState(path2, true);
node2.add(node6);
assertEquals(0, cache.getRowForPath(path1));
assertEquals(1, cache.getRowForPath(path2));
assertEquals(2, cache.getRowForPath(path25));
-
if (!isHarmony()) {
assertEquals(3, cache.getRowForPath(path3));
assertEquals(4, cache.getRowForPath(path4));
}
-
cache.treeStructureChanged(new TreeModelEvent(model, path2));
assertEquals(0, cache.getRowForPath(path1));
assertEquals(1, cache.getRowForPath(path2));
@@ -1059,7 +999,6 @@
assertEquals(3, cache.getRowForPath(path26));
assertEquals(4, cache.getRowForPath(path3));
assertEquals(5, cache.getRowForPath(path4));
-
cache.treeStructureChanged(new TreeModelEvent(model, rootPath));
assertEquals(0, cache.getRowForPath(path1));
assertEquals(1, cache.getRowForPath(path2));
@@ -1073,17 +1012,13 @@
if (cache instanceof ConcreteLayoutCache) {
return;
}
-
root.add(node1);
root.add(node2);
node2.add(node3);
node2.add(node4);
-
TreeModel model = new DefaultTreeModel(root);
cache.setModel(model);
cache.setExpandedState(path2, true);
cache.invalidateSizes();
}
-
}
-
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/tree/DefaultMutableTreeNodeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/tree/DefaultMutableTreeNodeTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/tree/DefaultMutableTreeNodeTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/tree/DefaultMutableTreeNodeTest.java Sun Nov 26 12:15:43 2006
@@ -22,7 +22,6 @@
import java.util.Enumeration;
import java.util.NoSuchElementException;
-
import javax.swing.BasicSwingTestCase;
public class DefaultMutableTreeNodeTest extends BasicSwingTestCase {
@@ -32,10 +31,12 @@
super(name);
}
+ @Override
protected void setUp() throws Exception {
node = new DefaultMutableTreeNode();
}
+ @Override
protected void tearDown() throws Exception {
node = null;
}
@@ -50,14 +51,12 @@
assertEquals(0, node.getChildCount());
assertNull(node.userObject);
assertTrue(node.allowsChildren);
-
node = new DefaultMutableTreeNode("user object");
assertNull(node.parent);
assertNull(node.children);
assertEquals(0, node.getChildCount());
assertEquals("user object", node.userObject);
assertTrue(node.allowsChildren);
-
node = new DefaultMutableTreeNode("user object", false);
assertNull(node.parent);
assertNull(node.children);
@@ -69,71 +68,68 @@
public void testInsert() throws Exception {
DefaultMutableTreeNode root1 = new DefaultMutableTreeNode();
final DefaultMutableTreeNode root2 = new DefaultMutableTreeNode();
-
final DefaultMutableTreeNode insertingChild = new DefaultMutableTreeNode();
root1.add(insertingChild);
assertEquals(1, root1.getChildCount());
assertSame(root1, insertingChild.getParent());
-
root2.add(new DefaultMutableTreeNode());
root2.add(new DefaultMutableTreeNode());
assertEquals(2, root2.getChildCount());
-
root2.insert(insertingChild, 1);
assertEquals(3, root2.getChildCount());
assertEquals(0, root1.getChildCount());
assertSame(root2, insertingChild.getParent());
assertSame(insertingChild, root2.getChildAt(1));
-
root2.insert(insertingChild, 0);
assertEquals(3, root2.getChildCount());
assertSame(root2, insertingChild.getParent());
assertSame(insertingChild, root2.getChildAt(0));
-
root2.insert(insertingChild, 2);
assertEquals(3, root2.getChildCount());
assertSame(root2, insertingChild.getParent());
assertSame(insertingChild, root2.getChildAt(2));
-
testExceptionalCase(new ArrayIndexOutOfBoundsCase() {
+ @Override
public void exceptionalAction() throws Exception {
root2.insert(insertingChild, 3);
}
});
-
testExceptionalCase(new ArrayIndexOutOfBoundsCase() {
+ @Override
public void exceptionalAction() throws Exception {
new DefaultMutableTreeNode().insert(new DefaultMutableTreeNode(), 2);
}
});
testExceptionalCase(new ArrayIndexOutOfBoundsCase() {
+ @Override
public void exceptionalAction() throws Exception {
new DefaultMutableTreeNode().insert(new DefaultMutableTreeNode(), -1);
}
});
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
new DefaultMutableTreeNode().insert(null, 0);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.insert(child, 0);
-
child.insert(root, 0);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
root.insert(root, 0);
}
});
-
testExceptionalCase(new IllegalStateCase() {
+ @Override
public void exceptionalAction() throws Exception {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
root.setAllowsChildren(false);
@@ -147,25 +143,25 @@
node.add(child);
node.add(new DefaultMutableTreeNode());
assertEquals(2, node.getChildCount());
-
node.remove(1);
assertEquals(1, node.getChildCount());
-
node.remove(child);
assertEquals(0, node.getChildCount());
assertNull(child.getParent());
-
testExceptionalCase(new ArrayIndexOutOfBoundsCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.remove(0);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.remove(null);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.remove(new DefaultMutableTreeNode());
}
@@ -177,7 +173,6 @@
node.add(child);
assertSame(node, child.getParent());
assertEquals(1, node.getChildCount());
-
DefaultMutableTreeNode parent = new DefaultMutableTreeNode();
child.setParent(parent);
assertSame(parent, child.getParent());
@@ -194,19 +189,19 @@
root.add(child2);
assertSame(child1, root.getChildAt(0));
assertSame(child2, root.getChildAt(1));
-
DefaultMutableTreeNode child3 = new DefaultMutableTreeNode();
root.insert(child3, 1);
assertSame(child1, root.getChildAt(0));
assertSame(child3, root.getChildAt(1));
assertSame(child2, root.getChildAt(2));
-
testExceptionalCase(new ArrayIndexOutOfBoundsCase() {
+ @Override
public void exceptionalAction() throws Exception {
root.getChildAt(3);
}
});
testExceptionalCase(new ArrayIndexOutOfBoundsCase() {
+ @Override
public void exceptionalAction() throws Exception {
root.getChildAt(-1);
}
@@ -215,27 +210,23 @@
public void testGetChildCount() throws Exception {
assertEquals(0, node.getChildCount());
-
node.add(new DefaultMutableTreeNode());
assertEquals(1, node.getChildCount());
-
node.add(new DefaultMutableTreeNode());
assertEquals(2, node.getChildCount());
-
node.remove(0);
assertEquals(1, node.getChildCount());
}
public void testGetIndex() throws Exception {
assertEquals(-1, node.getIndex(new DefaultMutableTreeNode()));
-
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
node.add(new DefaultMutableTreeNode());
node.add(child);
node.add(new DefaultMutableTreeNode());
assertEquals(1, node.getIndex(child));
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.getIndex(null);
}
@@ -244,20 +235,17 @@
public void testChildren() throws Exception {
assertSame(DefaultMutableTreeNode.EMPTY_ENUMERATION, node.children());
-
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode();
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode();
node.add(child1);
node.add(child2);
-
- Enumeration children = node.children();
+ Enumeration<?> children = node.children();
assertSame(child1, children.nextElement());
assertSame(child2, children.nextElement());
}
public void testGetSetAllowsChildren() throws Exception {
assertTrue(node.getAllowsChildren());
-
node.add(new DefaultMutableTreeNode());
node.add(new DefaultMutableTreeNode());
node.setAllowsChildren(false);
@@ -265,11 +253,9 @@
assertEquals(0, node.getChildCount());
assertNotNull(node.children);
assertTrue(node.children.isEmpty());
-
node.setAllowsChildren(true);
assertTrue(node.getAllowsChildren());
assertEquals(0, node.getChildCount());
-
node.add(new DefaultMutableTreeNode());
node.setAllowsChildren(true);
assertEquals(1, node.getChildCount());
@@ -277,7 +263,6 @@
public void testGetSetUserObject() throws Exception {
assertNull(node.getUserObject());
-
Object user = new Object();
node.setUserObject(user);
assertSame(user, node.getUserObject());
@@ -289,7 +274,6 @@
node.add(new DefaultMutableTreeNode());
assertSame(root, node.getParent());
assertEquals(1, node.getChildCount());
-
node.removeFromParent();
assertNull(node.getParent());
assertEquals(1, node.getChildCount());
@@ -299,13 +283,11 @@
public void testRemoveAllChildren() throws Exception {
node.removeAllChildren();
assertEquals(0, node.getChildCount());
-
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode();
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode();
node.add(child1);
node.add(child2);
assertEquals(2, node.getChildCount());
-
node.removeAllChildren();
assertEquals(0, node.getChildCount());
assertNull(child1.getParent());
@@ -316,30 +298,27 @@
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode();
node.add(child1);
assertSame(child1, node.getChildAt(0));
-
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode();
node.add(child2);
assertSame(child2, node.getChildAt(1));
assertEquals(2, node.getChildCount());
-
node.add(child1);
assertEquals(2, node.getChildCount());
assertSame(child2, node.getChildAt(0));
assertSame(child1, node.getChildAt(1));
-
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
root.add(child1);
assertEquals(1, node.getChildCount());
assertEquals(1, root.getChildCount());
assertEquals(root, child1.getParent());
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.add(null);
}
});
-
testExceptionalCase(new IllegalStateCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.setAllowsChildren(false);
node.add(new DefaultMutableTreeNode());
@@ -351,16 +330,13 @@
assertFalse(node.isNodeAncestor(null));
assertFalse(node.isNodeAncestor(new DefaultMutableTreeNode()));
assertTrue(node.isNodeAncestor(node));
-
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
DefaultMutableTreeNode childChild = new DefaultMutableTreeNode();
node.add(child);
child.add(childChild);
-
assertTrue(childChild.isNodeAncestor(child));
assertTrue(child.isNodeAncestor(node));
assertTrue(childChild.isNodeAncestor(node));
-
child.setParent(null);
assertFalse(child.isNodeAncestor(node));
}
@@ -369,16 +345,13 @@
assertFalse(node.isNodeDescendant(null));
assertFalse(node.isNodeDescendant(new DefaultMutableTreeNode()));
assertTrue(node.isNodeDescendant(node));
-
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
DefaultMutableTreeNode childChild = new DefaultMutableTreeNode();
node.add(child);
child.add(childChild);
-
assertTrue(child.isNodeDescendant(childChild));
assertTrue(node.isNodeDescendant(child));
assertTrue(node.isNodeDescendant(childChild));
-
child.setParent(null);
assertFalse(node.isNodeDescendant(child));
}
@@ -386,13 +359,11 @@
public void testGetSharedAncestor() throws Exception {
assertNull(node.getSharedAncestor(null));
assertEquals(node, node.getSharedAncestor(node));
-
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
DefaultMutableTreeNode childChild = new DefaultMutableTreeNode();
root.add(child);
child.add(childChild);
-
DefaultMutableTreeNode nodeRoot = new DefaultMutableTreeNode();
nodeRoot.add(node);
child.add(nodeRoot);
@@ -401,7 +372,6 @@
assertEquals(child, child.getSharedAncestor(node));
assertEquals(child, childChild.getSharedAncestor(nodeRoot));
assertEquals(root, node.getSharedAncestor(root));
-
nodeRoot.setParent(null);
assertEquals(nodeRoot, node.getSharedAncestor(nodeRoot));
assertNull(node.getSharedAncestor(child));
@@ -410,13 +380,11 @@
public void testIsNodeRelated() throws Exception {
assertFalse(node.isNodeRelated(null));
assertTrue(node.isNodeRelated(node));
-
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
DefaultMutableTreeNode childChild = new DefaultMutableTreeNode();
root.add(child);
child.add(childChild);
-
DefaultMutableTreeNode nodeRoot = new DefaultMutableTreeNode();
nodeRoot.add(node);
child.add(nodeRoot);
@@ -425,7 +393,6 @@
assertTrue(child.isNodeRelated(node));
assertTrue(childChild.isNodeRelated(nodeRoot));
assertTrue(node.isNodeRelated(root));
-
nodeRoot.setParent(null);
assertTrue(node.isNodeRelated(nodeRoot));
assertFalse(node.isNodeRelated(child));
@@ -439,19 +406,15 @@
child.add(childChild);
child.add(node);
node.add(new DefaultMutableTreeNode());
-
assertEquals(1, node.getDepth());
assertEquals(2, child.getDepth());
assertEquals(3, root.getDepth());
-
DefaultMutableTreeNode childChildChild = new DefaultMutableTreeNode();
childChild.add(childChildChild);
assertEquals(3, root.getDepth());
-
DefaultMutableTreeNode childChildChildChild = new DefaultMutableTreeNode();
childChildChild.add(childChildChildChild);
assertEquals(4, root.getDepth());
-
assertEquals(0, childChildChildChild.getDepth());
}
@@ -462,7 +425,6 @@
root.add(child);
child.add(childChild);
child.add(node);
-
assertEquals(0, root.getLevel());
assertEquals(2, node.getLevel());
assertEquals(2, childChild.getLevel());
@@ -471,7 +433,6 @@
public void testGetPath() throws Exception {
assertEquals(1, node.getPath().length);
assertEquals(node, node.getPath()[0]);
-
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(child);
@@ -480,12 +441,10 @@
assertEquals(root, node.getPath()[0]);
assertEquals(child, node.getPath()[1]);
assertEquals(node, node.getPath()[2]);
-
child.setParent(null);
assertEquals(2, node.getPath().length);
assertSame(child, node.getPath()[0]);
assertSame(node, node.getPath()[1]);
-
DefaultMutableTreeNode otherRoot = new DefaultMutableTreeNode();
child.setParent(otherRoot);
assertEquals(3, node.getPath().length);
@@ -496,23 +455,19 @@
public void testGetPathToRoot() throws Exception {
DefaultMutableTreeNode anyNode = new DefaultMutableTreeNode();
-
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
root.add(node);
-
TreeNode[] path = anyNode.getPathToRoot(root, 100);
assertEquals(101, path.length);
assertSame(root, path[0]);
assertNull(path[1]);
assertNull(path[100]);
-
path = anyNode.getPathToRoot(node, 100);
assertEquals(102, path.length);
assertSame(root, path[0]);
assertSame(node, path[1]);
assertNull(path[2]);
assertNull(path[101]);
-
path = anyNode.getPathToRoot(null, 100);
assertEquals(100, path.length);
}
@@ -521,11 +476,9 @@
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
DefaultMutableTreeNode node = new DefaultMutableTreeNode("node");
root.add(node);
-
Object[] path = root.getUserObjectPath();
assertEquals(1, path.length);
assertSame(root.getUserObject(), path[0]);
-
path = node.getUserObjectPath();
assertEquals(2, path.length);
assertSame(root.getUserObject(), path[0]);
@@ -537,7 +490,6 @@
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(child);
child.add(node);
-
assertSame(root, root.getRoot());
assertSame(root, child.getRoot());
assertSame(root, node.getRoot());
@@ -547,7 +499,6 @@
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(child);
-
assertFalse(child.isRoot());
assertTrue(root.isRoot());
assertTrue(node.isRoot());
@@ -560,7 +511,6 @@
root.add(child);
child.add(childChild);
root.add(node);
-
assertNull(node.getNextNode());
assertSame(child, root.getNextNode());
assertSame(childChild, child.getNextNode());
@@ -574,7 +524,6 @@
root.add(child);
child.add(childChild);
root.add(node);
-
assertSame(childChild, node.getPreviousNode());
assertSame(child, childChild.getPreviousNode());
assertSame(root, child.getPreviousNode());
@@ -588,42 +537,35 @@
root.add(child);
child.add(childChild);
root.add(node);
-
- Enumeration preEnum = node.preorderEnumeration();
+ Enumeration<?> preEnum = node.preorderEnumeration();
assertSame(node, preEnum.nextElement());
assertFalse(preEnum.hasMoreElements());
-
preEnum = childChild.preorderEnumeration();
assertSame(childChild, preEnum.nextElement());
assertFalse(preEnum.hasMoreElements());
-
preEnum = child.preorderEnumeration();
assertSame(child, preEnum.nextElement());
assertSame(childChild, preEnum.nextElement());
assertFalse(preEnum.hasMoreElements());
-
-
preEnum = root.preorderEnumeration();
assertSame(root, preEnum.nextElement());
assertSame(child, preEnum.nextElement());
assertSame(childChild, preEnum.nextElement());
assertSame(node, preEnum.nextElement());
assertFalse(preEnum.hasMoreElements());
-
preEnum = root.preorderEnumeration();
root.remove(0);
assertSame(root, preEnum.nextElement());
assertSame(node, preEnum.nextElement());
assertFalse(preEnum.hasMoreElements());
-
preEnum = node.preorderEnumeration();
root.remove(0);
assertSame(node, preEnum.nextElement());
assertFalse(preEnum.hasMoreElements());
-
testExceptionalCase(new ExceptionalCase() {
+ @Override
public void exceptionalAction() throws Exception {
- Enumeration preEnum = node.preorderEnumeration();
+ Enumeration<?> preEnum = node.preorderEnumeration();
preEnum.nextElement();
preEnum.nextElement();
}
@@ -639,25 +581,20 @@
child.add(childChild);
root.add(node);
node.add(nodeChild);
-
- Enumeration postEnum = node.postorderEnumeration();
+ Enumeration<?> postEnum = node.postorderEnumeration();
assertSame(nodeChild, postEnum.nextElement());
assertSame(node, postEnum.nextElement());
assertFalse(postEnum.hasMoreElements());
-
postEnum = nodeChild.postorderEnumeration();
assertSame(nodeChild, postEnum.nextElement());
assertFalse(postEnum.hasMoreElements());
-
postEnum = childChild.postorderEnumeration();
assertSame(childChild, postEnum.nextElement());
assertFalse(postEnum.hasMoreElements());
-
postEnum = child.postorderEnumeration();
assertSame(childChild, postEnum.nextElement());
assertSame(child, postEnum.nextElement());
assertFalse(postEnum.hasMoreElements());
-
postEnum = root.postorderEnumeration();
assertSame(childChild, postEnum.nextElement());
assertSame(child, postEnum.nextElement());
@@ -665,8 +602,8 @@
assertSame(node, postEnum.nextElement());
assertSame(root, postEnum.nextElement());
assertFalse(postEnum.hasMoreElements());
-
- final DefaultMutableTreeNode nodeChildChild = new DefaultMutableTreeNode("nodeChildChild");
+ final DefaultMutableTreeNode nodeChildChild = new DefaultMutableTreeNode(
+ "nodeChildChild");
nodeChild.add(nodeChildChild);
postEnum = root.postorderEnumeration();
assertSame(childChild, postEnum.nextElement());
@@ -676,7 +613,6 @@
assertSame(node, postEnum.nextElement());
assertSame(root, postEnum.nextElement());
assertFalse(postEnum.hasMoreElements());
-
DefaultMutableTreeNode childChild2 = new DefaultMutableTreeNode("childChild2");
child.add(childChild2);
postEnum = root.postorderEnumeration();
@@ -688,11 +624,11 @@
assertSame(node, postEnum.nextElement());
assertSame(root, postEnum.nextElement());
assertFalse(postEnum.hasMoreElements());
-
if (isHarmony()) {
testExceptionalCase(new ExceptionalCase() {
+ @Override
public void exceptionalAction() throws Exception {
- Enumeration postEnum = nodeChildChild.postorderEnumeration();
+ Enumeration<?> postEnum = nodeChildChild.postorderEnumeration();
postEnum.nextElement();
postEnum.nextElement();
}
@@ -709,25 +645,20 @@
child.add(childChild);
root.add(node);
node.add(nodeChild);
-
- Enumeration depthEnum = node.depthFirstEnumeration();
+ Enumeration<?> depthEnum = node.depthFirstEnumeration();
assertSame(nodeChild, depthEnum.nextElement());
assertSame(node, depthEnum.nextElement());
assertFalse(depthEnum.hasMoreElements());
-
depthEnum = nodeChild.depthFirstEnumeration();
assertSame(nodeChild, depthEnum.nextElement());
assertFalse(depthEnum.hasMoreElements());
-
depthEnum = childChild.depthFirstEnumeration();
assertSame(childChild, depthEnum.nextElement());
assertFalse(depthEnum.hasMoreElements());
-
depthEnum = child.depthFirstEnumeration();
assertSame(childChild, depthEnum.nextElement());
assertSame(child, depthEnum.nextElement());
assertFalse(depthEnum.hasMoreElements());
-
depthEnum = root.depthFirstEnumeration();
assertSame(childChild, depthEnum.nextElement());
assertSame(child, depthEnum.nextElement());
@@ -735,8 +666,8 @@
assertSame(node, depthEnum.nextElement());
assertSame(root, depthEnum.nextElement());
assertFalse(depthEnum.hasMoreElements());
-
- final DefaultMutableTreeNode nodeChildChild = new DefaultMutableTreeNode("nodeChildChild");
+ final DefaultMutableTreeNode nodeChildChild = new DefaultMutableTreeNode(
+ "nodeChildChild");
nodeChild.add(nodeChildChild);
depthEnum = root.depthFirstEnumeration();
assertSame(childChild, depthEnum.nextElement());
@@ -746,7 +677,6 @@
assertSame(node, depthEnum.nextElement());
assertSame(root, depthEnum.nextElement());
assertFalse(depthEnum.hasMoreElements());
-
DefaultMutableTreeNode childChild2 = new DefaultMutableTreeNode("childChild2");
child.add(childChild2);
depthEnum = root.depthFirstEnumeration();
@@ -758,11 +688,11 @@
assertSame(node, depthEnum.nextElement());
assertSame(root, depthEnum.nextElement());
assertFalse(depthEnum.hasMoreElements());
-
if (isHarmony()) {
testExceptionalCase(new ExceptionalCase() {
+ @Override
public void exceptionalAction() throws Exception {
- Enumeration depthEnum = nodeChildChild.depthFirstEnumeration();
+ Enumeration<?> depthEnum = nodeChildChild.depthFirstEnumeration();
depthEnum.nextElement();
depthEnum.nextElement();
}
@@ -779,30 +709,28 @@
child.add(childChild);
root.add(node);
node.add(nodeChild);
-
- Enumeration pathEnum = node.pathFromAncestorEnumeration(root);
+ Enumeration<?> pathEnum = node.pathFromAncestorEnumeration(root);
assertSame(root, pathEnum.nextElement());
assertSame(node, pathEnum.nextElement());
assertFalse(pathEnum.hasMoreElements());
-
pathEnum = childChild.pathFromAncestorEnumeration(root);
assertSame(root, pathEnum.nextElement());
assertSame(child, pathEnum.nextElement());
assertSame(childChild, pathEnum.nextElement());
assertFalse(pathEnum.hasMoreElements());
-
pathEnum = childChild.pathFromAncestorEnumeration(childChild);
assertSame(childChild, pathEnum.nextElement());
assertFalse(pathEnum.hasMoreElements());
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.pathFromAncestorEnumeration(new DefaultMutableTreeNode());
}
});
testExceptionalCase(new ExceptionalCase() {
+ @Override
public void exceptionalAction() throws Exception {
- Enumeration pathEnum = node.pathFromAncestorEnumeration(node);
+ Enumeration<?> pathEnum = node.pathFromAncestorEnumeration(node);
pathEnum.nextElement();
pathEnum.nextElement();
}
@@ -818,25 +746,20 @@
child.add(childChild);
root.add(node);
node.add(nodeChild);
-
- Enumeration breadthEnum = node.breadthFirstEnumeration();
+ Enumeration<?> breadthEnum = node.breadthFirstEnumeration();
assertSame(node, breadthEnum.nextElement());
assertSame(nodeChild, breadthEnum.nextElement());
assertFalse(breadthEnum.hasMoreElements());
-
breadthEnum = nodeChild.breadthFirstEnumeration();
assertSame(nodeChild, breadthEnum.nextElement());
assertFalse(breadthEnum.hasMoreElements());
-
breadthEnum = childChild.breadthFirstEnumeration();
assertSame(childChild, breadthEnum.nextElement());
assertFalse(breadthEnum.hasMoreElements());
-
breadthEnum = child.breadthFirstEnumeration();
assertSame(child, breadthEnum.nextElement());
assertSame(childChild, breadthEnum.nextElement());
assertFalse(breadthEnum.hasMoreElements());
-
breadthEnum = root.breadthFirstEnumeration();
assertSame(root, breadthEnum.nextElement());
assertSame(child, breadthEnum.nextElement());
@@ -844,8 +767,8 @@
assertSame(childChild, breadthEnum.nextElement());
assertSame(nodeChild, breadthEnum.nextElement());
assertFalse(breadthEnum.hasMoreElements());
-
- final DefaultMutableTreeNode childChildChild = new DefaultMutableTreeNode("childChildChild");
+ final DefaultMutableTreeNode childChildChild = new DefaultMutableTreeNode(
+ "childChildChild");
childChild.add(childChildChild);
breadthEnum = root.breadthFirstEnumeration();
assertSame(root, breadthEnum.nextElement());
@@ -855,7 +778,6 @@
assertSame(nodeChild, breadthEnum.nextElement());
assertSame(childChildChild, breadthEnum.nextElement());
assertFalse(breadthEnum.hasMoreElements());
-
DefaultMutableTreeNode childChild2 = new DefaultMutableTreeNode("childChild2");
child.add(childChild2);
breadthEnum = root.breadthFirstEnumeration();
@@ -867,10 +789,10 @@
assertSame(nodeChild, breadthEnum.nextElement());
assertSame(childChildChild, breadthEnum.nextElement());
assertFalse(breadthEnum.hasMoreElements());
-
testExceptionalCase(new ExceptionalCase() {
+ @Override
public void exceptionalAction() throws Exception {
- Enumeration breadthEnum = childChildChild.breadthFirstEnumeration();
+ Enumeration<?> breadthEnum = childChildChild.breadthFirstEnumeration();
breadthEnum.nextElement();
breadthEnum.nextElement();
}
@@ -880,11 +802,9 @@
public void testIsNodeChild() throws Exception {
assertFalse(node.isNodeChild(null));
assertFalse(node.isNodeChild(node));
-
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
child.setParent(node);
assertFalse(node.isNodeChild(child));
-
child.setParent(null);
node.add(child);
assertTrue(node.isNodeChild(child));
@@ -895,10 +815,9 @@
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(node);
root.add(child);
-
assertSame(node, root.getFirstChild());
-
testExceptionalCase(new NoSuchElementCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.getFirstChild();
}
@@ -910,10 +829,9 @@
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(child);
root.add(node);
-
assertSame(node, root.getLastChild());
-
testExceptionalCase(new NoSuchElementCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.getLastChild();
}
@@ -927,17 +845,17 @@
root.add(child1);
root.add(node);
root.add(child3);
-
assertEquals(node, root.getChildAfter(child1));
assertEquals(child3, root.getChildAfter(node));
assertNull(root.getChildAfter(child3));
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.getChildAfter(null);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.getChildAfter(new DefaultMutableTreeNode());
}
@@ -951,18 +869,17 @@
root.add(child1);
root.add(node);
root.add(child3);
-
assertNull(root.getChildBefore(child1));
assertEquals(child1, root.getChildBefore(node));
assertEquals(node, root.getChildBefore(child3));
-
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.getChildBefore(null);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
node.getChildBefore(new DefaultMutableTreeNode());
}
@@ -972,25 +889,21 @@
public void testIsNodeSibling() throws Exception {
assertFalse(node.isNodeSibling(null));
assertTrue(node.isNodeSibling(node));
-
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(child);
root.add(node);
assertTrue(node.isNodeSibling(child));
assertTrue(child.isNodeSibling(node));
-
node.setParent(null);
assertFalse(child.isNodeSibling(node));
}
public void testGetSiblingCount() throws Exception {
assertEquals(1, node.getSiblingCount());
-
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
root.add(node);
assertEquals(1, node.getSiblingCount());
-
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(child);
assertEquals(2, node.getSiblingCount());
@@ -1002,7 +915,6 @@
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(child);
root.add(node);
-
assertNull(root.getNextSibling());
assertSame(node, child.getNextSibling());
assertNull(node.getNextSibling());
@@ -1013,11 +925,9 @@
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
root.add(child);
root.add(node);
-
assertNull(root.getPreviousSibling());
assertSame(child, node.getPreviousSibling());
assertNull(child.getPreviousSibling());
-
node.setParent(null);
assertNull(node.getPreviousSibling());
}
@@ -1035,7 +945,6 @@
root.add(child);
root.add(node);
child.add(childChild);
-
assertSame(childChild, root.getFirstLeaf());
assertSame(childChild, child.getFirstLeaf());
assertSame(node, node.getFirstLeaf());
@@ -1048,7 +957,6 @@
root.add(node);
root.add(child);
child.add(childChild);
-
assertSame(node, node.getLastLeaf());
assertSame(childChild, root.getLastLeaf());
assertSame(childChild, child.getLastLeaf());
@@ -1063,7 +971,6 @@
root.add(child);
child.add(childChild);
node.add(nodeChild);
-
assertNull(root.getNextLeaf());
assertSame(childChild, node.getNextLeaf());
assertNull(child.getNextLeaf());
@@ -1080,7 +987,6 @@
root.add(child);
child.add(childChild);
node.add(nodeChild);
-
assertNull(node.getPreviousLeaf());
assertNull(root.getPreviousLeaf());
assertSame(nodeChild, child.getPreviousLeaf());
@@ -1097,7 +1003,6 @@
root.add(child);
child.add(childChild);
node.add(nodeChild);
-
assertEquals(2, root.getLeafCount());
assertEquals(1, child.getLeafCount());
assertEquals(1, nodeChild.getLeafCount());
@@ -1105,7 +1010,6 @@
public void testToString() throws Exception {
assertNull(node.toString());
-
node.setUserObject("user object");
assertEquals("user object", node.toString());
}
@@ -1117,28 +1021,32 @@
node.add(child);
Object userObject = new Object();
node.setUserObject(userObject);
-
- DefaultMutableTreeNode clone = (DefaultMutableTreeNode)node.clone();
+ DefaultMutableTreeNode clone = (DefaultMutableTreeNode) node.clone();
assertNull(clone.getParent());
assertEquals(0, clone.getChildCount());
assertSame(userObject, clone.getUserObject());
}
-
private abstract class ArrayIndexOutOfBoundsCase extends ExceptionalCase {
- public Class expectedExceptionClass() {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<?> expectedExceptionClass() {
return ArrayIndexOutOfBoundsException.class;
}
}
private abstract class IllegalStateCase extends ExceptionalCase {
- public Class expectedExceptionClass() {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<?> expectedExceptionClass() {
return IllegalStateException.class;
}
}
private abstract class NoSuchElementCase extends ExceptionalCase {
- public Class expectedExceptionClass() {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<?> expectedExceptionClass() {
return NoSuchElementException.class;
}
}