From: Nat P. <nat...@b1...> - 2002-11-19 16:14:14
|
Here's some ideas for the API. interface Overloaded { void overloaded( int number ); void overloaded( String text ); void notOverloaded( int number ); } Mock mock = new Mock( Overloaded.class ); Set up expectations on overloaded methods: mock.expectVoid( "overloaded", new Class[]{int.class}, P.args(P.eq(1)) ); mock.expectVoid( "overloaded", new Class[]{String.class}, P.args(P.eq("1")) ); Can ignore argument types if there is only one method with a given name: mock.expectVoid( "notOverloaded", P.args(P.eq(2)) ); But specifying argument types will have the same effect: mock.expectVoid( "notOverloaded", new Class[]{int.class}, P.args(P.eq(2)) ); Ignoring argument types for overloaded methods will throw an AssertionFailedError: expectFail( "invalid argument types", new Runnable() { public void run() { mock.expectVoid( "overloaded", P.args(P.eq(1)) ); } } Specifying argument types that are not used by any methods will throw an AssertionFailedError: expectFail( "invalid argument types", new Runnable() { public void run() { mock.expectVoid( "overloaded", new Class[]{bool.class}, P.args(P.eq(true)) ); } } And similarly for the setupXXX methods. Cheers, Nat. -- Nat Pryce <nat...@b1...> B13media |