title: Ref & Key issues when mock testing with objectify entity models
body: <p>I am not sure if I should just flat out not be doing this but I am usually used to mocking a lot of areas of my application and am running into issues when I use Ref and Keys inside of my entities.</p>
  
  <p>I have followed the pattern in the <a href="https://code.google.com/p/objectify-appengine/wiki/Entities" rel="nofollow">docs</a> where you use a ref in the entity but you mask the ref so you can get access to the driver object it references like so: </p>
  
  <pre><code>@Entity
  class Car {
      @Id Long id;
      @Load Ref&lt;Person&gt; driver;    // Person is an @Entity
  
      public Person getDriver() { return driver.get(); }
      public void setDriver(Person value) { driver = Ref.create(value); }
  }
  </code></pre>
  
  <p>My particular scenario is working with an importer where I am parsing xml and building up my entities ready to save them.  As my unit tests are only actually testing the import and parsing of the xml I mock out my dao implementations so that I am not actually using the datastore.</p>
  
  <p>I then run into issues when I have called setDriver which just creates a Ref object.  I then use the getDriver method which will return null as the Ref.get has a direct dependency on the datastore.  </p>
  
  <p>Has anyone ever come across this problem and is there any way to create a mock Ref object?  I was considering not having a direct reference to Ref in my entity and instead having a reference to a helper class that can provide a Ref that I have control over in my tests?  </p>