Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrains/726460 to your computer and use it in GitHub Desktop.
Save jbrains/726460 to your computer and use it in GitHub Desktop.
public class CreateActionTest {
def mockery = new JUnit4Mockery();
def modelRepository = mockery.mock(ModelRepository.class); // corresponds to class methods on Model in Rails
def model = new Model(); // treated as Entity (DDD sense)
def controller = new Controller(modelRepository);
@Before
public void supposeModelRepositoryCreatesOurModelObject() {
mockery.stub(modelRepository).create().will(returnValue(model));
}
@Test
public void savesModelByExpectingThenActing() throws Exception {
mockery.oneOf(modelRepository).save(with(same(model)));
controller.create();
}
@Test
public void savesModelByActingThenVerifying() throws Exception {
controller.create();
mockery.verify(modelRepository).save(with(same(model)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment