tiebin-zhang / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

EasyMock API order between static mock and non-static mock #322

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
@RunWith(PowerMockRunner.class)
@PrepareForTest({RepositoryCompte.class})
public class ClientTest {

       /** Class under test */
       private Client client;

       private BankAccount mock;

       private String numAccount = "0002333899";

       @Before
       public void setUp() throws Exception {
               PowerMock.mockStaticStrict(RepositoryAccount.class);
               mock = PowerMock.createStrictMock(BankAccount .class);
               client = new Client(mock);
       }

       @Test
       public void testCreateNewAccount() throws
AccountNotAvailableException {

EasyMock.expect(RepositoryAccount.isAvailable(numAccount)).andReturn(true);
               mock.addNewAccount(numAccount);
               PowerMock.replay(RepositoryAccount.class, mock);
               client.createNewAccount(numAccount);
               PowerMock.verify(RepositoryAccount.class, mock);
       }
}
and my method I need to test the behavior :

      public void createNewAccount(String numAccount)
       throws AccountNotAvailableException {
               if (!RepositoryAccount.isAvailable(numAccount)) { // inst 1
                       throw new AccountNotAvailableException();
               }
               bankAccount.addNewAccount(numAccount); // inst 2
       }

I would like that RepositoryAccount.isAvailable(numAccount) be
strictly called before bankAccount.addNewAccount(numAccount);

Original issue reported on code.google.com by johan.ha...@gmail.com on 11 Apr 2011 at 10:25