title: Is EasyMock's .times(x) method an issue for unit testing robustness?
body: <p>I'm currently working on some unit tests for my application using JUnit and EasyMock for mocking complex objects, and I'm facing a <strong>dilemma</strong>. 
  For instance, I'm testing each function with the following test template:</p>
  
  <pre><code>public static int foo(Object a){
  // my function that needs to be tested
  
    int quantity = 0;
    if(a != null &amp;&amp; a.getInt() != null ){
      quantity = a.getInt();
    }
    return quantity;
  
  }
  
  public void testFoo(){
  // my unit test for the function foo
    int expectedValue = 0;
    int output = 0;
  
  //Setting up my mocks
    Object a_mock = EasyMock.create(Object.class)
    EasyMock.expect(a_mock.getInt()).andReturn(null).times(1);
    EasyMock.expect(a_mock.getInt()).andReturn(1).times(2);
  
  //Executing
    // Case 1: a is null
    expectedValue = 0;
    output = foo(null);
    assertEquals(expectedValue, output);
  
    // Case 2: a.getIn() is null
    expectedValue = 0;
    output = foo(a_mock);
    assertEquals(expectedValue, output);
  
    //Case 3: nominal case
    expectedValue = 1;
    output = foo(a_mock);
    assertEquals(expectedValue, output);
  
  }
  </code></pre>
  
  <p>This structure works pretty well, but here is my point: unit testing is a testing process that allows you to validate if each unit (here a function) gives you the wanted output, knowing the input. This means that if I need to modify my function foo, but without modifying what it does, my unit tests still have to pass.
  Theoretically, if foo is changed like this:</p>
  
  <pre><code>public static int foo(Object a){
  
    int quantity = 0;
    if(a != null &amp;&amp; a.getInt() != null &amp;&amp; a.getInt() != 5){ //modification here
      quantity = a.getInt();
    }
    return quantity;
  
  }
  </code></pre>
  
  <p>Then testFoo still has to pass.
  <strong>But it doesn't</strong>, because the <code>.times(2)</code> must be changed in <code>.times(3)</code>.</p>
  
  <p>So here is my question : is the .times(x) method of EasyMock an issue for the robustness of unit tests ? And if no, then what is the minimal level of robustness a unit test must have ?</p>