title: Need some help with some basic PowerMock / EasyMock problems
body: <p>I'm relatively new to the world of PowerMock / EasyMock, and something I thought should be relatively straight-forward just isn't working. Perhaps someone can show me where I'm going wrong.</p>
  
  <p>Consider these two classes:</p>
  
  <pre><code>public class Foo
  {
      public int doStuff(int a)
      {
          return (5 / a);
      }
  }
  
  public class Bar
  {
      public void doSomething()
      {
          Foo foo = new Foo();
          int c = foo.doStuff(0);
      }
  }
  </code></pre>
  
  <p>Now, in the test class, I want to test the Bar method doSomething. The problem I've got is its use of Foo. As you can see, passing a 0 to Foo will result in a divide by zero error. I'd like to stub out / suppress Foo.doStuff() so that this doesn't happen. All I really need to do is ensure that doStuff() actually gets called. So, I've done this:</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest({ Foo.class })                 
  
  public class TestStuff
  {
  
  @Test
  public void testOtherStuff() throws Exception
  {
  
      Foo fooMock = PowerMock.createMock(Foo.class);
      expectNew(Foo.class).andReturn(fooMock);
      EasyMock.expect(fooMock.doStuff(anyInt())).andReturn(1);
      //fooMock.doStuff(anyInt());
  
      //suppress (method(Foo.class, "doStuff"));
  
      replayAll();
  
      Bar bar = new Bar();
      bar.doSomething();
  
      verifyAll();
  }
  }
  </code></pre>
  
  <p>When I run this I've getting the divide by zero exception. I had thought that using the expect() call, and specifying the return value of 1 would prevent the method from being executed. This is obviously not the case. So the first question is, why not?</p>
  
  <p>So then I tried doing the statements that are commented out above. That is, I commented out the expect() call, and used the other two statements, thinking that I had to suppress execution of the method. I found that if I didn't do the suppress() statement I would always get the divide by zero exception. However, by having the suppress statement in there, I get an assertionerror, where it says that doStuff was expected to be called 1 time, and the actual calls were 0.</p>
  
  <p>So, why isn't the method counted as executed?</p>
  
  <p>How do I get the mock stuff to "stub" the method so that it counts as being executed by doesn't really do anything?</p>
  
  <p>The situation I've been dealing with actually has a void return on doStuff. How to the necessary mock statements differ for handling methods with no return value, versus those that do?</p>
  
  <p>It seems like I'm on the cusp of making this work, but I feel like I've got some kind of incorrect combination of statements being tried here. I've hit my head on this, read a bunch of examples, and I'm still coming up short.</p>
  
  <p>Any help?</p>
  
  <p>Thanks,</p>
  
  <p>Craig</p>