/** Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { TextTitle t = new TextTitle("Title"); XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); XYTitleAnnotation a2 = (XYTitleAnnotation) a1.clone(); assertNotSame(a1, a2); assertSame(a1.getClass(), a2.getClass()); assertEquals(a1, a2); }
/** Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { TextTitle t = new TextTitle("Title"); XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); XYTitleAnnotation a2 = new XYTitleAnnotation(1.0, 2.0, t); assertEquals(a1, a2); int h1 = a1.hashCode(); int h2 = a2.hashCode(); assertEquals(h1, h2); }
/** Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { TextTitle t = new TextTitle("Title"); XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); XYTitleAnnotation a2 = new XYTitleAnnotation(1.0, 2.0, t); assertEquals(a1, a2); a1 = new XYTitleAnnotation(1.1, 2.0, t); assertFalse(a1.equals(a2)); a2 = new XYTitleAnnotation(1.1, 2.0, t); assertEquals(a1, a2); a1 = new XYTitleAnnotation(1.1, 2.2, t); assertFalse(a1.equals(a2)); a2 = new XYTitleAnnotation(1.1, 2.2, t); assertEquals(a1, a2); TextTitle t2 = new TextTitle("Title 2"); a1 = new XYTitleAnnotation(1.1, 2.2, t2); assertFalse(a1.equals(a2)); a2 = new XYTitleAnnotation(1.1, 2.2, t2); assertEquals(a1, a2); }