Is any difference in using one() or oneOf() in JMock?
Cheat sheet says that:
oneOf = The invocation is expected once and once only.
exactly(n).of = The invocation is expected exactly n times. Note: one is convenient shorthand for exactly(1).
In tests I can see using one and in other there is oneOf. The question is if there is any difference between this keywords or it means equaly the same thing.
In cheat sheet mentioned before there is also example:
oneOf (calculator).add(1, 1); will(returnValue(2));
oneOf (calculator).add(2, 2); will(returnValue(5));
Which probably says that oneOf means that I expect that could be more invocations of method add and in this case there are two invocations (one of them is with parameters 1 and 1, and second with parameters 2 and 2).
But the exactly one aka exactly(1).of exactly one could mean, that in one test method I EXPECT ONLY ONE calling of that method.
Maybe it's just my missunderstanding of the the definition.
There's no differences. oneOf(mockObject)
is just an alias for exactly(1).of(mockObject)
.
Take a look at source code of AbstractExpectations.java