title: Using EasyMock with recursive method
body: <p>I am using a series of Strict Mocks generated with EasyMock 3.2 to test a method that call's itself recursively. By setting the expectations of my mocks I can control the method so that it only calls itself once and then exits. However, I am seeing some very strange behaviour from EasyMock which looks like a bug, where it get's confused about the number of times a method is expected.</p>
  
  <p>For example:</p>
  
  <pre><code>final Collection srcCollection = EasyMock.createStrictMock(Collection.class);
  final NativeBroker broker = EasyMock.createMockBuilder(NativeBroker.class)
      .addMockedMethod("getCollection")
      .addMockedMethod("getSubject")
      .createStrictMock();
  
  expect(srcCollection.getURI()).andReturn(src);
  
  replay(srcCollection, broker);
  
  //run the test
  broker.checkPermissionsForCopy(srcCollection, dest, newName);
  
  verify(srcCollection, broker);
  </code></pre>
  
  <p>Leads to the error from EasyMock:</p>
  
  <pre><code>java.lang.AssertionError: 
      Expectation failure on verify:
          Collection.getURI(): expected: 2, actual: 1
          at org.easymock.internal.MocksControl.verify(MocksControl.java:226)
          at org.easymock.EasyMock.verify(EasyMock.java:2080)
  </code></pre>
  
  <p>I have only instructed EasyMock to expect one result, so why does it think I want two? I also get the same error if I change my expectation to this:</p>
  
  <pre><code>expect(srcCollection.getURI()).andReturn(src).once();
  </code></pre>
  
  <p>...And it get's stranger...</p>
  
  <p>If I change my expectation to this:</p>
  
  <pre><code>expect(srcCollection.getURI()).andReturn(src).times(2);
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>java.lang.AssertionError: 
      Expectation failure on verify:
          Collection.getURI(): expected: 3, actual: 1
          at org.easymock.internal.MocksControl.verify(MocksControl.java:226)
          at org.easymock.EasyMock.verify(EasyMock.java:2080)
  </code></pre>
  
  <p>And, further if I change my expectation to this:</p>
  
  <pre><code>expect(srcCollection.getURI()).andReturn(src).anyTimes();
  </code></pre>
  
  <p>I get an even stranger error:</p>
  
  <pre><code>java.lang.IllegalStateException: last method called on mock already has a non-fixed count set.
      at org.easymock.internal.MocksControl.replay(MocksControl.java:216)
      at org.easymock.EasyMock.replay(EasyMock.java:2012)
  </code></pre>
  
  <p>Does anyone have any suggestions, or know of any limitations with EasyMock in recursive functions?</p>