title: Proper way to compare object in a Unit test
body: <p>I'm writing unit tests for my grails application, and I realized I don't really know the proper way to assert whether an object is the proper object or not.</p>
  
  <p>For example, given this test:</p>
  
  <pre><code>void testExampleTest() {
      mockSession.person = new Person(firstName:'John', lastName:'Doe', middleInitial:'E')
      def model = controller.testMethod()
      ...assertions...
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>def testMethod = {
      Person currPerson = session.getAttribute("person")
      render(view:'view',model:[person:currPerson]
  }
  </code></pre>
  
  <p>how should I make sure that the person object I added to the session is properly being passed in the model? Is it sufficient to use</p>
  
  <pre><code>assertEquals( person,model['person'] )
  </code></pre>
  
  <p>or because I injected the object myself into the session does it make more sense to use</p>
  
  <pre><code>assertEquals( person.firstName, model['person'].firstName )
  assertEquals( person.lastName, model['person'].lastName )
  assertequals( person.middleName, model['person'].middleName )
  </code></pre>
  
  <p>It seems to me that the first way should suffice as long as the object has a properly defined equals method, but I just wanted to see what the conventional way is.</p>
  
  <p>Thanks</p>