1 | public class MiddlePinNeedleTests extends TestCase {↵ | | 1 | public class PlumNeedleTests extends TestCase {↵
|
| | | 2 | ↵
|
2 | /**↵ | | 3 | /**↵
|
3 | * Returns the tests as a test suite.↵ | | 4 | * Returns the tests as a test suite.↵
|
4 | *↵ | | 5 | *↵
|
5 | * @return The test suite.↵ | | 6 | * @return The test suite.↵
|
6 | */↵ | | 7 | */↵
|
7 | public static Test suite() {↵ | | 8 | public static Test suite() {↵
|
8 | return new TestSuite(MiddlePinNeedleTests.class);↵ | | 9 | return new TestSuite(PlumNeedleTests.class);↵
|
9 | }↵ | | 10 | }↵
|
|
10 | /**↵ | | 11 | /**↵
|
11 | * Constructs a new set of tests.↵ | | 12 | * Constructs a new set of tests.↵
|
12 | *↵ | | 13 | *↵
|
13 | * @param name the name of the tests.↵ | | 14 | * @param name the name of the tests.↵
|
14 | */↵ | | 15 | */↵
|
15 | public MiddlePinNeedleTests(String name) {↵ | | 16 | public PlumNeedleTests(String name) {↵
|
16 | super(name);↵ | | 17 | super(name);↵
|
17 | }↵ | | 18 | }↵
|
|
18 | /**↵ | | 19 | /**↵
|
19 | * Check that the equals() method can distinguish all fields.↵ | | 20 | * Check that the equals() method can distinguish all fields.↵
|
20 | */↵ | | 21 | */↵
|
21 | public void testEquals() {↵ | | 22 | public void testEquals() {↵
|
22 | MiddlePinNeedle n1 = new MiddlePinNeedle();↵ | | 23 | PlumNeedle n1 = new PlumNeedle();↵
|
23 | MiddlePinNeedle n2 = new MiddlePinNeedle();↵ | | 24 | PlumNeedle n2 = new PlumNeedle();↵
|
24 | assertTrue(n1.equals(n2));↵ | | 25 | assertTrue(n1.equals(n2));↵
|
25 | assertTrue(n2.equals(n1));↵ | | 26 | assertTrue(n2.equals(n1));↵
|
26 | }↵ | | 27 | }↵
|
|
27 | /**↵ | | 28 | /**↵
|
28 | * Check that cloning works.↵ | | 29 | * Check that cloning works.↵
|
29 | */↵ | | 30 | */↵
|
30 | public void testCloning() {↵ | | 31 | public void testCloning() {↵
|
31 | MiddlePinNeedle n1 = new MiddlePinNeedle();↵ | | 32 | PlumNeedle n1 = new PlumNeedle();↵
|
32 | MiddlePinNeedle n2 = null;↵ | | 33 | PlumNeedle n2 = null;↵
|
33 | try {↵ | | 34 | try {↵
|
34 | n2 = (MiddlePinNeedle) n1.clone();↵ | | 35 | n2 = (PlumNeedle) n1.clone();↵
|
35 | }↵ | | 36 | }↵
|
36 | catch (CloneNotSupportedException e) {↵ | | 37 | catch (CloneNotSupportedException e) {↵
|
37 | e.printStackTrace();↵ | | 38 | e.printStackTrace();↵
|
38 | System.err.println("Failed to clone.");↵ | | 39 | System.err.println("Failed to clone.");↵
|
39 | }↵ | | 40 | }↵
|
40 | assertTrue(n1 != n2);↵ | | 41 | assertTrue(n1 != n2);↵
|
41 | assertTrue(n1.getClass() == n2.getClass());↵ | | 42 | assertTrue(n1.getClass() == n2.getClass());↵
|
42 | assertTrue(n1.equals(n2));↵ | | 43 | assertTrue(n1.equals(n2));↵
|
43 | }↵ | | 44 | }↵
|
|
44 | /**↵ | | 45 | /**↵
|
45 | * Serialize an instance, restore it, and check for equality.↵ | | 46 | * Serialize an instance, restore it, and check for equality.↵
|
46 | */↵ | | 47 | */↵
|
47 | public void testSerialization() {↵ | | 48 | public void testSerialization() {↵
|
48 | MiddlePinNeedle n1 = new MiddlePinNeedle();↵ | | 49 | PlumNeedle n1 = new PlumNeedle();↵
|
49 | MiddlePinNeedle n2 = null;↵ | | 50 | PlumNeedle n2 = null;↵
|
50 | try {↵ | | 51 | try {↵
|
51 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵ | | 52 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵
|
52 | ObjectOutput out = new ObjectOutputStream(buffer);↵ | | 53 | ObjectOutput out = new ObjectOutputStream(buffer);↵
|
53 | out.writeObject(n1);↵ | | 54 | out.writeObject(n1);↵
|
54 | out.close();↵ | | 55 | out.close();↵
|
55 | ObjectInput in = new ObjectInputStream(↵ | | 56 | ObjectInput in = new ObjectInputStream(↵
|
56 | new ByteArrayInputStream(buffer.toByteArray())↵ | | 57 | new ByteArrayInputStream(buffer.toByteArray())↵
|
57 | );↵ | | 58 | );↵
|
58 | n2 = (MiddlePinNeedle) in.readObject();↵ | | 59 | n2 = (PlumNeedle) in.readObject();↵
|
59 | in.close();↵ | | 60 | in.close();↵
|
60 | }↵ | | 61 | }↵
|
61 | catch (Exception e) {↵ | | 62 | catch (Exception e) {↵
|
62 | e.printStackTrace();↵ | | 63 | e.printStackTrace();↵
|
63 | }↵ | | 64 | }↵
|
64 | assertTrue(n1.equals(n2)) | | 65 | assertTrue(n1.equals(n2))
|