|
From: Steve F. <st...@m3...> - 2002-11-18 00:21:34
|
Barry Kaplan wrote:
> Steve Freeman wrote:
> I'm still a bit confused. Consider:
>
> public void class QuantityHolder {
> public int getQuantity(Key key1, Key key1);
> }
>
> public int sum(QuantityHolder holder) {
> int result = holder.getQuantity("key1", "key2") +
> holder.getQuantity("key3", "key4") + ...;
> }
>
> I want to mock QuantityHolder. I want to ensure that sum() invoked the
> getQuantity method twice, with the correct keys, but in any order.
depends on quite what you want to test, for example:
ExpectationSet keys;
public int getQuantity(Key key1, Key key2) {
keys.addActual(key1);
keys.addActual(key2);
}
would test that all four keys were used, but not the combinations. In
practice, would that satisfy you that you'd covered the bases?
alternatively, how about a constraint:
P.or(
P.and(P.eq("key1"), P.eq("key2")),
P.and(P.eq("key3"), P.eq("key4")));
which tests that only the right combinations are passed through.
If the arguments are always in the same order, you could try:
ExpectationSet keys;
public int getQuantity(Key key1, Key key2) {
keys.addActual(key1 + key2);
}
Finally, if the arguments can come in any order but the pairs matter, I
think you could try:
ExpectationSet keys;
public int getQuantity(Key key1, Key key2) {
Set keySet = new HashSet();
keySet.add(key1);
keySet.add(key2);
keys.addActual(keySet);
}
> I don't see how the ExpectationSet can do this. How to specify the mock
> return value for each key1/key2 combination? Can I use the Constraints
> with ExpectationSet (for mulitple arguments)?
We're still thinking about this one, but it's an obvious direction to go.
>
> -bk
>
> BTW, are there any other examples floating around (ie, projects that
> make extensive use of mockobjects)? The ones the distribution are ok,
> but not too extensive.
not sure, but you could contribute some...
S.
|