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