1 42 43 package org.jfree.util.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.util.BooleanList; 57 58 61 public class BooleanListTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(BooleanListTests.class); 70 } 71 72 77 public BooleanListTests(final String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 86 final BooleanList l1 = new BooleanList(); 87 l1.setBoolean(0, Boolean.TRUE); 88 l1.setBoolean(1, Boolean.FALSE); 89 l1.setBoolean(2, null); 90 91 final BooleanList l2 = new BooleanList(); 92 l2.setBoolean(0, Boolean.TRUE); 93 l2.setBoolean(1, Boolean.FALSE); 94 l2.setBoolean(2, null); 95 96 assertTrue(l1.equals(l2)); 97 assertTrue(l2.equals(l2)); 98 99 } 100 101 102 105 public void testCloning() { 106 107 final BooleanList l1 = new BooleanList(); 108 l1.setBoolean(0, Boolean.TRUE); 109 l1.setBoolean(1, Boolean.FALSE); 110 l1.setBoolean(2, null); 111 112 BooleanList l2 = null; 113 try { 114 l2 = (BooleanList) l1.clone(); 115 } 116 catch (CloneNotSupportedException e) { 117 System.err.println("BooleanListTests.testCloning: failed to clone."); 118 } 119 assertTrue(l1 != l2); 120 assertTrue(l1.getClass() == l2.getClass()); 121 assertTrue(l1.equals(l2)); 122 123 l2.setBoolean(0, Boolean.FALSE); 124 assertFalse(l1.equals(l2)); 125 126 } 127 128 131 public void testSerialization() { 132 133 final BooleanList l1 = new BooleanList(); 134 l1.setBoolean(0, Boolean.TRUE); 135 l1.setBoolean(1, Boolean.FALSE); 136 l1.setBoolean(2, null); 137 138 BooleanList l2 = null; 139 140 try { 141 final ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 142 final ObjectOutput out = new ObjectOutputStream (buffer); 143 out.writeObject(l1); 144 out.close(); 145 146 final ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 147 l2 = (BooleanList) in.readObject(); 148 in.close(); 149 } 150 catch (Exception e) { 151 System.out.println(e.toString()); 152 } 153 assertEquals(l1, l2); 154 155 } 156 157 } 158 | Popular Tags |