1 43 44 package org.jfree.chart.block.junit; 45 46 import java.awt.Color ; 47 import java.awt.GradientPaint ; 48 import java.io.ByteArrayInputStream ; 49 import java.io.ByteArrayOutputStream ; 50 import java.io.ObjectInput ; 51 import java.io.ObjectInputStream ; 52 import java.io.ObjectOutput ; 53 import java.io.ObjectOutputStream ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.chart.block.BlockBorder; 60 import org.jfree.ui.RectangleInsets; 61 import org.jfree.util.UnitType; 62 63 66 public class BlockBorderTests extends TestCase { 67 68 73 public static Test suite() { 74 return new TestSuite(BlockBorderTests.class); 75 } 76 77 82 public BlockBorderTests(String name) { 83 super(name); 84 } 85 86 89 public void testEquals() { 90 BlockBorder b1 = new BlockBorder( 91 new RectangleInsets(1.0, 2.0, 3.0, 4.0), Color.red 92 ); 93 BlockBorder b2 = new BlockBorder( 94 new RectangleInsets(1.0, 2.0, 3.0, 4.0), Color.red 95 ); 96 assertTrue(b1.equals(b2)); 97 assertTrue(b2.equals(b2)); 98 99 b1 = new BlockBorder( 101 new RectangleInsets(UnitType.RELATIVE, 1.0, 2.0, 3.0, 4.0), 102 Color.red 103 ); 104 assertFalse(b1.equals(b2)); 105 b2 = new BlockBorder( 106 new RectangleInsets(UnitType.RELATIVE, 1.0, 2.0, 3.0, 4.0), 107 Color.red 108 ); 109 assertTrue(b1.equals(b2)); 110 111 b1 = new BlockBorder( 113 new RectangleInsets(1.0, 2.0, 3.0, 4.0), Color.blue 114 ); 115 assertFalse(b1.equals(b2)); 116 b2 = new BlockBorder( 117 new RectangleInsets(1.0, 2.0, 3.0, 4.0), Color.blue 118 ); 119 assertTrue(b1.equals(b2)); 120 } 121 122 125 public void testCloning() { 126 BlockBorder b1 = new BlockBorder(); 127 assertFalse(b1 instanceof Cloneable ); 128 } 129 130 133 public void testSerialization() { 134 BlockBorder b1 = new BlockBorder( 135 new RectangleInsets(1.0, 2.0, 3.0, 4.0), 136 new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow) 137 ); 138 BlockBorder b2 = null; 139 try { 140 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 141 ObjectOutput out = new ObjectOutputStream (buffer); 142 out.writeObject(b1); 143 out.close(); 144 145 ObjectInput in = new ObjectInputStream ( 146 new ByteArrayInputStream (buffer.toByteArray()) 147 ); 148 b2 = (BlockBorder) in.readObject(); 149 in.close(); 150 } 151 catch (Exception e) { 152 fail(e.toString()); 153 } 154 assertTrue(b1.equals(b2)); 155 } 156 157 } 158 | Popular Tags |