Skip to content

Instantly share code, notes, and snippets.

@derkork
Created March 25, 2015 08:00
Show Gist options
  • Save derkork/45d7fba64b54a41608e1 to your computer and use it in GitHub Desktop.
Save derkork/45d7fba64b54a41608e1 to your computer and use it in GitHub Desktop.
Testing service implementations without creating a spring context.
class SomeServiceImplTest extends Specification {
SomeServiceImpl underTest
SomeDao someDao
SomeOtherService someOtherService
void setup() {
// create the instance under test
underTest = new SomeServiceImpl()
// mock all dependencies and inject them
someDao = Mock(SomeDao)
someOtherService = Mock(SomeOtherService)
underTest.someDao = someDao;
underTest.someOtherService = someOtherService
}
void "Test that save invokes the Dao"() {
when:
someService.save("SomeValue")
then:
1 * someDao.save("SomeValue")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment