From: Joakim O. <joa...@ag...> - 2006-05-18 07:10:45
|
I have been thinking a little bit about features in java 1.5 that could be used in rMock. One feature that I think would be very cool is to use annotations on your live interfaces that are also understood by rMock. The idea is perhaps best illustrated by an example: public interface MyInterface { @constraint(argument=3D0 constraints=3D {"NOT_NULL", ">12", "<4711"}) void myCannotBeNullMethod(Integer value); } The in rMock when you writhe this code: MyInterface myMock =3D mock(MyInterface.class, "myInterface"); myMock.myCannotBeNullMethod(null); startVerification(); The expectation will be: myInterface.myCannotBeNullMethod(!NULL && greaterThan(12) && lessThan(4711)= ) The pros: * less modifications * The contract is visible on the interface and in the javadoc. * The contract is automatically adhered to in tests The cons: * Only works in java 1.5 * Java 1.5 annotations does have a limited syntax (although I am not yet fluent in it). Any thoughs? |