Menu

#4 Declarable defaults

open
nobody
None
3
2006-04-07
2006-04-07
No

I find myself writing code similar to this quite often:

testSomething() {
OutputStream targetOutputStream =
(OutputStream)intrecept(ByteArrayOutputStream.class,
"targetOutputStream");

OutpuStreamFactory factory =
(OutputStreamFactory)mock(OutputStreamFactory.class,
"factory");
factory.create();
modify().returnValue(targetOutputStream);

os.close();

startVerification();

/* perform test */
}

Today rMock has default return-values in some instances
(ie if an expectation is recorded for a method that
returns an interface rMock automatically creates a mock
for the returned interface). I would like this
functionality to be extended:

Be able to declare default return values for other
situations. One example that would make the above case
simpler (semantics are just for demonstration, can most
likely be better):

default.when(is.method.returning(OutputStream.class)).perform(action.returnIntercepted(ByteArrayOutputStream.class));

Discussion


Log in to post a comment.