📄 legenditemtests.java
字号:
false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false,
Color.black, true, Color.blue, new BasicStroke(1.2f), true,
new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
Color.green);
assertFalse(item1.equals(item2));
item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL",
false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false,
Color.black, true, Color.blue, new BasicStroke(1.2f), true,
new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
Color.green);
assertTrue(item1.equals(item2));
item1 = new LegendItem("Label2", "Description2", "ToolTip",
"URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0),
false, Color.black, false, Color.blue, new BasicStroke(1.2f),
true, new Line2D.Double(1.0, 2.0, 3.0, 4.0),
new BasicStroke(2.1f), Color.green);
assertFalse(item1.equals(item2));
item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL",
false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false,
Color.black, false, Color.blue, new BasicStroke(1.2f), true,
new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
Color.green);
assertTrue(item1.equals(item2));
item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL",
false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false,
Color.black, false, Color.yellow, new BasicStroke(1.2f), true,
new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
Color.green);
assertFalse(item1.equals(item2));
item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL",
false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false,
Color.black, false, Color.yellow, new BasicStroke(1.2f), true,
new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
Color.green);
assertTrue(item1.equals(item2));
item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL",
false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false,
Color.black, false, Color.yellow, new BasicStroke(2.1f), true,
new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
Color.green);
assertFalse(item1.equals(item2));
item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL",
false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false,
Color.black, false, Color.yellow, new BasicStroke(2.1f), true,
new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
Color.green);
assertTrue(item1.equals(item2));
item1 = new LegendItem("Label2", "Description2", "ToolTip",
"URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0),
false, Color.black, false, Color.yellow, new BasicStroke(2.1f),
false, new Line2D.Double(1.0, 2.0, 3.0, 4.0),
new BasicStroke(2.1f), Color.green);
assertFalse(item1.equals(item2));
item2 = new LegendItem("Label2", "Description2", "ToolTip",
"URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0),
false, Color.black, false, Color.yellow, new BasicStroke(2.1f),
false, new Line2D.Double(1.0, 2.0, 3.0, 4.0),
new BasicStroke(2.1f), Color.green);
assertTrue(item1.equals(item2));
item1 = new LegendItem("Label2", "Description2", "ToolTip",
"URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0),
false, Color.black, false, Color.yellow, new BasicStroke(2.1f),
false, new Line2D.Double(4.0, 3.0, 2.0, 1.0),
new BasicStroke(2.1f), Color.green);
assertFalse(item1.equals(item2));
item2 = new LegendItem("Label2", "Description2", "ToolTip",
"URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0),
false, Color.black, false, Color.yellow, new BasicStroke(2.1f),
false, new Line2D.Double(4.0, 3.0, 2.0, 1.0),
new BasicStroke(2.1f), Color.green);
assertTrue(item1.equals(item2));
item1 = new LegendItem("Label2", "Description2", "ToolTip",
"URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0),
false, Color.black, false, Color.yellow, new BasicStroke(2.1f),
false, new Line2D.Double(4.0, 3.0, 2.0, 1.0),
new BasicStroke(3.3f), Color.green);
assertFalse(item1.equals(item2));
item2 = new LegendItem("Label2", "Description2", "ToolTip",
"URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0),
false, Color.black, false, Color.yellow, new BasicStroke(2.1f),
false, new Line2D.Double(4.0, 3.0, 2.0, 1.0),
new BasicStroke(3.3f), Color.green);
assertTrue(item1.equals(item2));
item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL",
false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false,
Color.black, false, Color.yellow, new BasicStroke(2.1f), false,
new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f),
Color.white
);
assertFalse(item1.equals(item2));
item2 = new LegendItem("Label2", "Description2", "ToolTip",
"URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0),
false, Color.black, false, Color.yellow, new BasicStroke(2.1f),
false, new Line2D.Double(4.0, 3.0, 2.0, 1.0),
new BasicStroke(3.3f),
Color.white);
assertTrue(item1.equals(item2));
}
/**
* Serialize an instance, restore it, and check for equality.
*/
public void testSerialization() {
LegendItem item1 = new LegendItem("Item", "Description",
"ToolTip", "URL",
new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), Color.red);
LegendItem item2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(item1);
out.close();
ObjectInput in = new ObjectInputStream(
new ByteArrayInputStream(buffer.toByteArray())
);
item2 = (LegendItem) in.readObject();
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertEquals(item1, item2);
}
/**
* Serialize an instance, restore it, and check for equality.
*/
public void testSerialization2() {
AttributedString as = new AttributedString("Test String");
as.addAttribute(TextAttribute.FONT, new Font("Dialog", Font.PLAIN, 12));
LegendItem item1 = new LegendItem(as, "Description", "ToolTip", "URL",
new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), Color.red);
LegendItem item2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(item1);
out.close();
ObjectInput in = new ObjectInputStream(
new ByteArrayInputStream(buffer.toByteArray())
);
item2 = (LegendItem) in.readObject();
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertEquals(item1, item2);
}
/**
* Cloning is not required for this class as it is designed to be
* immutable.
*/
public void testCloning() {
LegendItem item = new LegendItem("Item", "Description",
"ToolTip", "URL",
new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), Color.red);
assertFalse(item instanceof Cloneable);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -