Student implements Serializable { @Override public boolean equals(final Object inputObject) { boolean isEqual = false; if (this == inputObject) { isEqual = true; } else if (inputObject != null && getClass() == inputObject.getClass()) { final Student inputStudent = (Student) inputObject; if (this.getStudentId() == inputStudent.getStudentId()) { isEqual = true; } } return isEqual; } Student(final int studentId, final String name, final char grade); int getStudentId(); void setStudentId(final int studentId); String getName(); void setName(final String name); char getGrade(); void setGrade(final char grade); @Override boolean equals(final Object inputObject); @Override int hashCode(); @Override String toString();  }
@Test public void testEquality() throws Exception { final Student firstStudent = new Student(1, "Adam", 'A'); final Student secondStudent = new Student(2, "Donald", 'B'); final Student secondSameStudent = new Student(2, "Donald", 'B'); final Student firstSameStudent = firstStudent; assertTrue(firstStudent.equals(firstSameStudent)); assertFalse(firstStudent.equals(secondStudent)); assertTrue(secondStudent.equals(secondSameStudent)); }