1 42 43 package org.jfree.chart.block.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.block.EmptyBlock; 57 58 61 public class EmptyBlockTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(EmptyBlockTests.class); 70 } 71 72 77 public EmptyBlockTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 EmptyBlock b1 = new EmptyBlock(1.0, 2.0); 86 EmptyBlock b2 = new EmptyBlock(1.0, 2.0); 87 assertTrue(b1.equals(b2)); 88 assertTrue(b2.equals(b2)); 89 90 b1 = new EmptyBlock(1.1, 2.0); 91 assertFalse(b1.equals(b2)); 92 b2 = new EmptyBlock(1.1, 2.0); 93 assertTrue(b1.equals(b2)); 94 95 b1 = new EmptyBlock(1.1, 2.2); 96 assertFalse(b1.equals(b2)); 97 b2 = new EmptyBlock(1.1, 2.2); 98 assertTrue(b1.equals(b2)); 99 } 100 101 104 public void testCloning() { 105 EmptyBlock b1 = new EmptyBlock(1.0, 2.0); 106 EmptyBlock b2 = null; 107 108 try { 109 b2 = (EmptyBlock) b1.clone(); 110 } 111 catch (CloneNotSupportedException e) { 112 fail(e.toString()); 113 } 114 assertTrue(b1 != b2); 115 assertTrue(b1.getClass() == b2.getClass()); 116 assertTrue(b1.equals(b2)); 117 } 118 119 122 public void testSerialization() { 123 EmptyBlock b1 = new EmptyBlock(1.0, 2.0); 124 EmptyBlock b2 = null; 125 try { 126 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 127 ObjectOutput out = new ObjectOutputStream (buffer); 128 out.writeObject(b1); 129 out.close(); 130 131 ObjectInput in = new ObjectInputStream ( 132 new ByteArrayInputStream (buffer.toByteArray()) 133 ); 134 b2 = (EmptyBlock) in.readObject(); 135 in.close(); 136 } 137 catch (Exception e) { 138 fail(e.toString()); 139 } 140 assertEquals(b1, b2); 141 } 142 143 } 144 | Popular Tags |