@Test
public void happyCase() throws Exception {
// given
final SimpleObject simpleObject = new SimpleObject();
final Sequence seq = context.sequence("create");
context.checking(new Expectations() {
{
oneOf(mockContainer).newTransientInstance(SimpleObject.class);
inSequence(seq);
will(returnValue(simpleObject));
oneOf(mockContainer).persistIfNotAlready(simpleObject);
inSequence(seq);
}
});
// when
final SimpleObject obj = simpleObjects.create("Foobar");
// then
assertThat(obj, is(simpleObject));
assertThat(obj.getName(), is("Foobar"));
}