1 | public class StandardDialRangeTests extends TestCase {↵ | | 1 | public class IntervalXYDelegateTests 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(StandardDialRangeTests.class);↵ | | 8 | return new TestSuite(IntervalXYDelegateTests.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 StandardDialRangeTests(String name) {↵ | | 15 | public IntervalXYDelegateTests(String name) {↵
|
16 | super(name);↵ | | 16 | super(name);↵
|
17 | }↵ | | 17 | }↵
|
|
18 | /**↵ | | 18 | /**↵
|
19 | * Confirm that the equals method can distinguish all the required fields.↵ | | 19 | * Confirm that the equals method can distinguish all the required fields.↵
|
20 | */↵ | | 20 | */↵
|
21 | public void testEquals() {↵ | | 21 | public void testEquals() {↵
|
22 | StandardDialRange r1 = new StandardDialRange();↵ | | 22 | ↵
|
23 | StandardDialRange r2 = new StandardDialRange();↵ | | |
|
24 | assertTrue(r1.equals(r2)↵ | | 23 | XYSeries s1 = new XYSeries("Series");↵
|
| | | 24 | s1.add(1.2, 3.4);↵
|
| | | 25 | XYSeriesCollection c1 = new XYSeriesCollection();↵
|
| | | 26 | c1.addSeries(s1);↵
|
25 | );↵ | | 27 | IntervalXYDelegate d1 = new IntervalXYDelegate(c1);↵
|
|
26 | ↵ | | 28 | ↵
|
27 | // lowerBound↵ | | |
|
28 | r1.setLowerBound(1.1);↵ | | |
|
29 | assertFalse(r1.equals(r2));↵ | | |
|
30 | r2.setLowerBound(1.1);↵ | | |
|
31 | ↵ | | 29 | XYSeries s2 = new XYSeries("Series");↵
|
| | | 30 | XYSeriesCollection c2 = new XYSeriesCollection();↵
|
| | | 31 | s2.add(1.2, 3.4);↵
|
| | | 32 | c2.addSeries(s2);↵
|
| | | 33 | IntervalXYDelegate d2 = new IntervalXYDelegate(c2);↵
|
| | | 34 | ↵
|
32 | assertTrue(r1.equals(r2));↵ | | 35 | assertTrue(d1.equals(d2));↵
|
33 | ↵ | | 36 | ↵
|
34 | // upperBound↵ | | 37 | assertTrue(d2.equals(d1));↵
|
| | | 38 | ↵
|
35 | r1.setUpperBound(11.1);↵ | | 39 | d1.setAutoWidth(false);↵
|
36 | assertFalse(r1.equals(r2));↵ | | 40 | assertFalse(d1.equals(d2));↵
|
37 | r2.setUpperBound(11.1);↵ | | 41 | d2.setAutoWidth(false);↵
|
38 | assertTrue(r1.equals(r2));↵ | | 42 | assertTrue(d1.equals(d2));↵
|
39 | ↵ | | 43 | ↵
|
40 | // paint↵ | | 44 | ↵
|
41 | r1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, ↵ | | |
|
42 | Color.blue));↵ | | 45 | d1.setIntervalPositionFactor(0.123);↵
|
43 | assertFalse(r1.equals(r2));↵ | | 46 | assertFalse(d1.equals(d2));↵
|
44 | r2.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, ↵ | | 47 | d2.set↵
|
45 | Color.blue));↵ | | 48 | IntervalPositionFactor(0.123);↵
|
46 | assertTrue(r1.equals(r2));↵ | | 49 | assertTrue(d1.equals(d2));↵
|
47 | ↵ | | 50 | ↵
|
48 | ↵ | | |
|
49 | // check an inherited attribute↵ | | 51 | ↵
|
50 | r1.setVisible(false);↵ | | 52 | d1.setFixedIntervalWidth(1.23);↵
|
51 | assertFalse(r1.equals(r2));↵ | | 53 | assertFalse(d1.equals(d2));↵
|
52 | r2.setVisible(false);↵ | | 54 | d2.setFixedIntervalWidth(1.23);↵
|
53 | assertTrue(r1.equals(r2));↵ | | 55 | assertTrue(d1.equals(d2));↵
|
54 | }↵ | | 56 | }↵
|
55 | ↵ | | |
|
56 | /**↵ | | 57 | /**↵
|
57 | * Two objects that are equal are required to return the same hashCode. ↵ | | 58 | * Confirm that cloning works.↵
|
58 | */↵ | | 59 | */↵
|
59 | public void testHashCode() {↵ | | 60 | public void testCloning() {↵
|
60 | StandardDialRange r1 = new StandardDialRange();↵ | | 61 | ↵
|
61 | StandardDialRange r2 = new StandardDialRange();↵ | | |
|
62 | assertTrue(r1.equals(r2));↵ | | |
|
63 | int h1 = r1.hashCode();↵ | | |
|
64 | int h2 = r2.hashCode↵ | | |
|
| | | 62 | XYSeries s1 = new XYSeries("Series");↵
|
| | | 63 | s1.add(1.2, 3.4);↵
|
65 | ();↵ | | 64 | XYSeriesCollection c1 = new XYSeriesCollection();↵
|
66 | assertEquals(h1, h2);↵ | | 65 | c1.addSeries(s1);↵
|
67 | }↵ | | 66 | ↵
|
|
68 | /**↵ | | 67 | ↵
|
69 | * Confirm that cloning works.↵ | | |
|
70 | */↵ | | |
|
71 | public void testCloning() {↵ | | |
|
72 | StandardDialRange r1 = new StandardDialRange();↵ | | 68 | IntervalXYDelegate d1 = new ↵
|
73 | StandardDialRang↵ | | 69 | IntervalXYDelegate(c1);↵
|
| | | 70 | ↵
|
74 | e r2 = null;↵ | | 71 | IntervalXYDelegate d2 = null;↵
|
75 | try {↵ | | 72 | try {↵
|
76 | r2 = (StandardDialRange) r1.clone();↵ | | 73 | d2 = (IntervalXYDelegate) d1.clone();↵
|
77 | }↵ | | 74 | }↵
|
78 | catch (CloneNotSupportedException e) {↵ | | 75 | catch (CloneNotSupportedException e) {↵
|
79 | e.printStackTrace();↵ | | 76 | System.err.println("Failed to clone.");↵
|
80 | }↵ | | 77 | }↵
|
81 | assertTrue(r1 != r2);↵ | | 78 | assertTrue(d1 != d2);↵
|
82 | assertTrue(r1.getClass() == r2.getClass());↵ | | 79 | assertTrue(d1.getClass() == d2.getClass());↵
|
83 | assertTrue(r1.equals(r2));↵ | | 80 | assertTrue(d1.equals(d2));↵
|
84 | ↵ | | 81 | }↵
|
|
85 | ↵ | | 82 | /**↵
|
86 | // check that the listener lists are independent↵ | | 83 | ↵
|
87 | MyDialLayerChangeListener l1 = new MyDialLayerChangeListener();↵ | | |
|
88 | r1.addChangeListener(l1);↵ | | |
|
89 | assertTrue(r1.hasListener(l1));↵ | | |
|
90 | assertFalse(r2.hasListener(l1)↵ | | 84 | * Serialize an instance, restore it, and check for equality.↵
|
| | | 85 | */↵
|
| | | 86 | public void testSerialization() {↵
|
| | | 87 | XYSeries s1 = new XYSeries("Series");↵
|
91 | );↵ | | 88 | s1.add(1.2, 3.4);↵
|
92 | }↵ | | 89 | ↵
|
|
93 | /**↵ | | 90 | ↵
|
94 | * Serialize an instance, restore it, and check for equality.↵ | | |
|
95 | */↵ | | |
|
96 | public void testSerialization() {↵ | | |
|
97 | StandardDialRang↵ | | 91 | XYSeriesCollection c1 = new XYSeriesCollection();↵
|
| | | 92 | c1.addSeries(s1);↵
|
98 | e r1 = new StandardDialRange();↵ | | 93 | IntervalXYDelegate d1 = new ↵
|
99 | StandardDialRang↵ | | 94 | IntervalXYDelegate(c1);↵
|
100 | e r2 = null;↵ | | 95 | IntervalXYDelegate d2 = null;↵
|
|
101 | try {↵ | | 96 | try {↵
|
102 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵ | | 97 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵
|
103 | ObjectOutput out = new ObjectOutputStream(buffer);↵ | | 98 | ObjectOutput out = new ObjectOutputStream(buffer);↵
|
104 | out.writeObject(r1);↵ | | 99 | out.writeObject(d1);↵
|
105 | out.close();↵ | | 100 | out.close();↵
|
|
106 | ObjectInput in = new ObjectInputStream(↵ | | 101 | ObjectInput in = new ObjectInputStream(↵
|
107 | new ByteArrayInputStream(buffer.toByteArray())↵ | | 102 | new ByteArrayInputStream(buffer.toByteArray())↵
|
108 | );↵ | | 103 | );↵
|
109 | r2 = (StandardDialRange) in.readObject();↵ | | 104 | d2 = (IntervalXYDelegate) in.readObject();↵
|
110 | in.close();↵ | | 105 | in.close();↵
|
111 | }↵ | | 106 | }↵
|
112 | catch (Exception e) {↵ | | 107 | catch (Exception e) {↵
|
113 | e.printStackTrace();↵ | | 108 | System.out.println(e.toString());↵
|
114 | }↵ | | 109 | }↵
|
115 | assertEquals(r1, r2) | | 110 | assertEquals(d1, d2)
|