### Question:
BaseOpenmrsObject implements Serializable, OpenmrsObject { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof BaseOpenmrsObject)) { return false; } BaseOpenmrsObject other = (BaseOpenmrsObject) obj; if (getUuid() == null) { return false; } Class<?> thisClass = Hibernate.getClass(this); Class<?> objClass = Hibernate.getClass(obj); if (!(thisClass.isAssignableFrom(objClass) || objClass.isAssignableFrom(thisClass))){ return false; } return getUuid().equals(other.getUuid()); }  @Override String getUuid(); @Override void setUuid(String uuid); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }### Answer:
@Test public void equals_shouldReturnFalseIfGivenObjIsNotInstanceOfBaseOpenmrsObject() { BaseOpenmrsObject o = new BaseOpenmrsObjectMock(); Object obj = new Object(); Assert.assertFalse(o.equals(obj)); }
@Test public void equals_shouldReturnFalseIfGivenObjIsNull() { BaseOpenmrsObject o = new BaseOpenmrsObjectMock(); BaseOpenmrsObject obj = null; Assert.assertFalse(o.equals(obj)); }
@Test public void equals_shouldReturnTrueIfObjectsAreTheSame() { BaseOpenmrsObject o = new BaseOpenmrsObjectMock(); BaseOpenmrsObject obj = o; Assert.assertTrue(o.equals(obj)); }
@Test public void shouldNotBeEqualWhenDifferentClassesAndSameId() { Encounter encounter = new Encounter(2); Order order = new Order(2); Assert.assertFalse(encounter.equals(order)); }
@Test public void shouldNotBeEqualWhenFirstIsNull() { Encounter encounter = new Encounter(2); Assert.assertFalse(encounter.equals(null)); }
@Test public void equals_shouldReturnfalseIfHibernateProxyOfOneThingIsComparedtoHibernateProxyofSomething() { SessionFactory sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory"); Session session = sessionFactory.getCurrentSession(); Assert.assertFalse((session.load(Patient.class, 2)).equals((session.load(Concept.class, 11)))); }
@Test public void equals_shouldReturnTrueIfHibernateProxyOfOneObjectComparedToNonHibernateProxyOfTheSameObject(){ SessionFactory sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory"); Session session = sessionFactory.getCurrentSession(); Patient patient = (Patient) session.get(Patient.class, 2); Patient patientproxyobject = (Patient) session.load(Patient.class, 2); Assert.assertTrue(patient.equals(patientproxyobject)); }
@Test public void equals_shouldReturnTrueIfHibernateProxyOfSomeObjectComparedToAnotherHibernateProxyOfTheSameObject(){ SessionFactory sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory"); Session session = sessionFactory.getCurrentSession(); Assert.assertTrue(session.load(Patient.class, 2).equals((session.load(Patient.class, 2)))) ; }