Port of schuchert.wikispaces.com


JMock-Verify_Method_Called_Exactly_Once

JMock-Verify_Method_Called_Exactly_Once

Verify a sequence of methods

This test method exists in a jMock_JUnit_4_Die_Skeleton.

Make sure that the testDoubleDie method will first have its roll() method called exactly once and then its getFaceValue() method called exactly once():

@Test
public void rollThenGetFaceValue() {
    context.checking(new Expectations() {
        {
            one(testDoubleDie).roll();
            one(testDoubleDie).getFaceValue();
        }
    });
    
    testDoubleDie.roll();
    testDoubleDie.getFaceValue();
}

Common fixture for the test

    Withdrawal withdrawal;
    Mockery context = new Mockery();

    BankAccount account;

    @Before
    public void initialize() {
        withdrawal = new Withdrawal();
        withdrawal.setAmount(1500);
        account = context.mock(BankAccount.class);
        withdrawal.setAccount(account);
    }


Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.