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.ColumnArrangement; 57 import org.jfree.chart.block.FlowArrangement; 58 import org.jfree.ui.HorizontalAlignment; 59 import org.jfree.ui.VerticalAlignment; 60 61 64 public class ColumnArrangementTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(ColumnArrangementTests.class); 73 } 74 75 80 public ColumnArrangementTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 ColumnArrangement c1 = new ColumnArrangement( 89 HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0 90 ); 91 ColumnArrangement c2 = new ColumnArrangement( 92 HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0 93 ); 94 assertTrue(c1.equals(c2)); 95 assertTrue(c2.equals(c1)); 96 97 c1 = new ColumnArrangement( 98 HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0 99 ); 100 assertFalse(c1.equals(c2)); 101 c2 = new ColumnArrangement( 102 HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0 103 ); 104 assertTrue(c1.equals(c2)); 105 106 c1 = new ColumnArrangement( 107 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0 108 ); 109 assertFalse(c1.equals(c2)); 110 c2 = new ColumnArrangement( 111 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0 112 ); 113 assertTrue(c1.equals(c2)); 114 115 c1 = new ColumnArrangement( 116 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0 117 ); 118 assertFalse(c1.equals(c2)); 119 c2 = new ColumnArrangement( 120 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0 121 ); 122 assertTrue(c1.equals(c2)); 123 124 c1 = new ColumnArrangement( 125 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2 126 ); 127 assertFalse(c1.equals(c2)); 128 c2 = new ColumnArrangement( 129 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2 130 ); 131 assertTrue(c1.equals(c2)); 132 133 } 134 135 138 public void testCloning() { 139 FlowArrangement f1 = new FlowArrangement(); 140 assertFalse(f1 instanceof Cloneable ); 141 } 142 143 146 public void testSerialization() { 147 FlowArrangement f1 = new FlowArrangement( 148 HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0 149 ); 150 FlowArrangement f2 = null; 151 try { 152 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 153 ObjectOutput out = new ObjectOutputStream (buffer); 154 out.writeObject(f1); 155 out.close(); 156 157 ObjectInput in = new ObjectInputStream ( 158 new ByteArrayInputStream (buffer.toByteArray()) 159 ); 160 f2 = (FlowArrangement) in.readObject(); 161 in.close(); 162 } 163 catch (Exception e) { 164 System.out.println(e.toString()); 165 } 166 assertEquals(f1, f2); 167 } 168 169 } 170 | Popular Tags |