/** * Problem that the equals(...) method distinguishes all fields. */ public void testEquals() { DateTitle t1 = new DateTitle(); DateTitle t2 = new DateTitle(); assertEquals(t1, t2); t1.setText("Test 1"); assertFalse(t1.equals(t2)); t2.setText("Test 1"); assertTrue(t1.equals(t2)); Font f = new Font("SansSerif", Font.PLAIN, 15); t1.setFont(f); assertFalse(t1.equals(t2)); t2.setFont(f); assertTrue(t1.equals(t2)); t1.setPaint(Color.blue); assertFalse(t1.equals(t2)); t2.setPaint(Color.blue); assertTrue(t1.equals(t2)); t1.setBackgroundPaint(Color.blue); assertFalse(t1.equals(t2)); t2.setBackgroundPaint(Color.blue); assertTrue(t1.equals(t2)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { DateTitle t1 = new DateTitle(); DateTitle t2 = new DateTitle(); assertTrue(t1.equals(t2)); int h1 = t1.hashCode(); int h2 = t2.hashCode(); assertEquals(h1, h2); }
/** * Check that the equals() method distinguishes all fields. */ public void testEquals() { DateTitle t1 = new DateTitle(); DateTitle t2 = new DateTitle(); assertEquals(t1, t2); t1.setText("Test 1"); assertFalse(t1.equals(t2)); t2.setText("Test 1"); assertTrue(t1.equals(t2)); Font f = new Font("SansSerif", Font.PLAIN, 15); t1.setFont(f); assertFalse(t1.equals(t2)); t2.setFont(f); assertTrue(t1.equals(t2)); t1.setPaint(Color.blue); assertFalse(t1.equals(t2)); t2.setPaint(Color.blue); assertTrue(t1.equals(t2)); t1.setBackgroundPaint(Color.blue); assertFalse(t1.equals(t2)); t2.setBackgroundPaint(Color.blue); assertTrue(t1.equals(t2)); }