| Method from org.jfree.io.junit.SerialUtilitiesTests Detail: |
public static Test suite() {
return new TestSuite(SerialUtilitiesTests.class);
}
Returns the tests as a test suite. |
public void testArc2DDoubleSerialization() {
Arc2D a1 = new Arc2D.Double(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, Arc2D.PIE);
Arc2D a2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(a1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
a2 = (Arc2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(a1, a2));
}
Serialize an Arc2D.Double instance and check that it
can be deserialized correctly. |
public void testArc2DFloatSerialization() {
Arc2D a1 = new Arc2D.Float(
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, Arc2D.PIE
);
Arc2D a2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(a1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
a2 = (Arc2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(a1, a2));
}
Serialize an Arc2D.Float instance and check that it
can be deserialized correctly. |
public void testColorSerialization() {
final Paint p1 = Color.blue;
Paint p2 = null;
try {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writePaint(p1, out);
out.close();
final ByteArrayInputStream bias = new ByteArrayInputStream(
buffer.toByteArray()
);
final ObjectInputStream in = new ObjectInputStream(bias);
p2 = SerialUtilities.readPaint(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertEquals(p1, p2);
}
Serialize a Color and check that it can be deserialized
correctly. |
public void testColorUIResourceSerialization() {
Paint p1 = UIManager.getColor("Panel.background");
Paint p2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writePaint(p1, out);
out.close();
ByteArrayInputStream bias = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bias);
p2 = SerialUtilities.readPaint(in);
in.close();
}
catch (Exception e) {
fail(e.toString());
}
assertEquals(p1, p2);
}
Serialize a ColorUIResource and check that it can be
deserialized correctly. |
public void testGeneralPathSerialization() {
GeneralPath g1 = new GeneralPath();
g1.moveTo(1.0f, 2.0f);
g1.lineTo(3.0f, 4.0f);
g1.curveTo(5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f);
g1.quadTo(1.0f, 2.0f, 3.0f, 4.0f);
g1.closePath();
GeneralPath g2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(g1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
g2 = (GeneralPath) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(g1, g2));
}
Some checks for the serialization of a GeneralPath instance. |
public void testGradientPaintSerialization() {
final Paint p1 = new GradientPaint(
0.0f, 0.0f, Color.blue, 100.0f, 200.0f, Color.red
);
Paint p2 = null;
try {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writePaint(p1, out);
out.close();
final ByteArrayInputStream bias = new ByteArrayInputStream(
buffer.toByteArray()
);
final ObjectInputStream in = new ObjectInputStream(bias);
p2 = SerialUtilities.readPaint(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
// we want to check that the two objects are equal, but can't rely on
// GradientPaint's equals() method because it is just the default
// method inherited from Object...
final GradientPaint gp1 = (GradientPaint) p1;
final GradientPaint gp2 = (GradientPaint) p2;
assertEquals(gp1.getColor1(), gp2.getColor1());
assertEquals(gp1.getPoint1(), gp2.getPoint1());
assertEquals(gp1.getColor2(), gp2.getColor2());
assertEquals(gp1.getPoint2(), gp2.getPoint2());
assertEquals(gp1.isCyclic(), gp2.isCyclic());
}
Serialize a GradientPaint, restore it, and check for
equality. |
public void testIsSerializable() {
assertTrue(SerialUtilities.isSerializable(Color.class));
assertTrue(SerialUtilities.isSerializable(ColorUIResource.class));
assertFalse(SerialUtilities.isSerializable(GradientPaint.class));
assertFalse(SerialUtilities.isSerializable(TexturePaint.class));
}
Tests the isSerializable(Class) method for some common cases. |
public void testLine2DDoubleSerialization() {
Line2D l1 = new Line2D.Double(1.0, 2.0, 3.0, 4.0);
Line2D l2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(l1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
l2 = (Line2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(l1, l2));
}
Serialize a Line2D.Double instance and check that it can be
deserialized correctly. |
public void testLine2DFloatSerialization() {
Line2D l1 = new Line2D.Float(1.0f, 2.0f, 3.0f, 4.0f);
Line2D l2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(l1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
l2 = (Line2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(l1, l2));
}
Serialize a Line2D.Float instance, and check that it can be
deserialized correctly. |
public void testRectangle2DDoubleSerialization() {
Rectangle2D r1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
Rectangle2D r2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(r1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
r2 = (Rectangle2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(r1, r2));
}
Serialize a Rectangle2D.Double instance and check that it
can be deserialized correctly. |
public void testRectangle2DFloatSerialization() {
Rectangle2D r1 = new Rectangle2D.Float(1.0f, 2.0f, 3.0f, 4.0f);
Rectangle2D r2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(r1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
r2 = (Rectangle2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(r1, r2));
}
Serialize a Rectangle2D.Float instance, and check that it
can be deserialized correctly. |
public void testTexturePaintSerialization() {
final Paint p1 = new TexturePaint(
new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB),
new Rectangle2D.Double(0, 0, 5, 5)
);
Paint p2 = null;
try {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writePaint(p1, out);
out.close();
final ByteArrayInputStream bias = new ByteArrayInputStream(
buffer.toByteArray()
);
final ObjectInputStream in = new ObjectInputStream(bias);
p2 = SerialUtilities.readPaint(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertNull(p2);
}
Serialize a TexturePaint, restore it, and check for
equality. Since this class is not serializable, we expect null as the
result. |