A quick play and it looks like you do not define order just that something should be expected. Each time you make a call to the mock it runs through every expectation in order until it finds one that matches and has not been called before.
So with:
expect(mMockBill.method1(eqBillMatcher("aa"))).andReturn("");
expect(mMockBill.method1(eqBillMatcher("aa"))).andReturn("");
expect(mMockBill.method1(eqBillMatcher("cc"))).andReturn("");
sut.doSomething("aa");
MATCH - expected[aa], actual[aa]
Just as you would expect. First match hits.
sut.doSomething("cc");
MISMATCH - expected[aa], actual[cc]
MISMATCH - expected[aa], actual[cc]
MATCH - expected[cc], actual[cc]
Each one in order (including ones that have already passed) until it finds a hit.
sut.doSomething("aa");
MATCH - expected[aa], actual[aa]
MATCH - expected[aa], actual[aa]
Each in order until it finds a hit that has not been called before.
This would enable it to provide the error messages on the lines of "unexpected method call, expected 1, actual 1 (+1).
--
Code for comment -
private boolean used = false;
<snip/>
public boolean matches(Object aActual) {
if (used) {
return false;
}
used = true;