The difference between EasyMock.expect (...). Times (...) compared to using EasyMock.expect (...) several times?

What is the difference between this:

ResultSet set = EasyMock.createNiceMock(ResultSet.class);
EasyMock.expect(set.getInt("col1")).andReturn(1);
EasyMock.expect(set.wasNull()).andReturn(false);
EasyMock.expect(set.getInt("col2")).andReturn(2);
EasyMock.expect(set.wasNull()).andReturn(false);
EasyMock.replay(set);

assertEquals(1, set.getInt("col1"));
assertEquals(false, set.wasNull());
assertEquals(2, set.getInt("col2"));
assertEquals(false, set.wasNull());

And this:

ResultSet set = EasyMock.createNiceMock(ResultSet.class);
EasyMock.expect(set.getInt("col1")).andReturn(1);
EasyMock.expect(set.getInt("col2")).andReturn(2);
EasyMock.expect(set.wasNull()).andReturn(false).times(2);
EasyMock.replay(set);

assertEquals(1, set.getInt("col1"));
assertEquals(false, set.wasNull());
assertEquals(2, set.getInt("col2"));
assertEquals(false, set.wasNull());

?

Note. Both sets of code compile and execute successfully as jUnit tests. Also, please note that using a β€œnice” layout is intentional here.

+5
source share
2 answers

To answer the question in your title, there is no difference. The call is x.expect(y).times(3)exactly the same as the call

x.expect(y);
x.expect(y);
x.expect(y);

(Note that, as Andy Thomas-Kramer pointed out, your specific examples are not exactly equivalent, because the order of the calls is different.)

. : times() . , - int, , . , expect() ( , ).

+8

-, . , , , .

+3

All Articles