title: Testing a method which uses another method from the same class
body: <p>Recently I have gotten into unit testing my applications and have found myself at a bit of a difficult spot design wise in one of my classes.</p>
  
  <p>I have a repository class which connects to the database, which looks a bit like this.</p>
  
  <pre><code>public interface Repository {
    ...
    void register(Account account)
    Account find(String email)
    ...
  }
  </code></pre>
  
  <p>which, in implementation does this:</p>
  
  <pre><code>public class RepositoryImpl implements Repository {
    ...
    public void register(Account account) {
      if (find(account.getEmail() != null) return;
      // Account with same email already exists.
      ...
    }
  }
  </code></pre>
  
  <p>This works fine in a live setting, but when unit testing it's a different story.</p>
  
  <p>I use Mockito for mocking my dependencies, but I cant seem to mock the <code>find</code> method in the implementation class.</p>
  
  <p>So my first thought was to inject a <code>Repository</code> in the <code>register</code> method which I than can fake, but that seems a bit weird since I provide a method with a class which it is a member of itself.</p>
  
  <p>After that I thought to just copy the <code>find</code> logic to the <code>register</code> method, but that violates the DRY principle.</p>
  
  <p>So.. any ideas on solving this design problem? I guess it's a common problem since it's quite standard to have unique emails in a system.</p>
  
  <p>Thanks!</p>