title: Unit testing, is it a good idea to verify methods are not called
body: <p>Let's say you've got the following method to test:</p>
  
  <pre><code>public void foo(object myObject, bool myBool)
  {
       if(myBool)
          repositoryA.save(myObject)
       else
          repositoryB.save(myObject)
  }
  </code></pre>
  
  <p>What is the best way to unit test such a function? If you write 2 tests 
   that assert repositoryA is called when myBool is true, and repositoryB is called when myBool is false, then the following change to the function would still make the tests pass but would potentially break the functionality of the application:</p>
  
  <pre><code>public void foo(object myObject, bool myBool)
  {
      repositoryA.save(myObject)
      repositoryB.save(myObject)
  }
  </code></pre>
  
  <p>On the other hand, if you assert that when myBool is true then repositoryA is called AND that repositoryB is not called, that gives you more confidence that any change to the function will not introduce bugs, but then you have a test which depends on implementation details. What's the best way to do it?</p>
  
  <p>And what if you use TDD, what tests would you write in order the reach the desired functionality?</p>