Skip to content

Instantly share code, notes, and snippets.

@OsaSoft
Created January 12, 2018 13:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OsaSoft/a2e1ea62f5fc58aec3988e2b8af8bda9 to your computer and use it in GitHub Desktop.
Save OsaSoft/a2e1ea62f5fc58aec3988e2b8af8bda9 to your computer and use it in GitHub Desktop.
Spock Spring workaround to using injected Spring beans in Where block
@SpringBootTest(classes = [ApplicationTest.class])
@ActiveProfiles("test")
class RepositoryTest {
@Autowired
IDeviceRepository deviceRepository
@Autowired
IGroupRepository groupRepository
@Autowired
IPlatformRepository platformRepository
@Autowired
IUserRepository userRepository
@Unroll
def "#repoName Repository is properly injected by Spring container"() {
given:
def repo = this."${repoName}Repository"
when:
repo.save(instance)
then:
repo.findOne(instance.id)
where:
repoName | instance
"device" | new Device(token: "token123")
"group" | new Group(name: "testGroup")
"platform" | new Platform(name: "testPlatform")
"user" | new User(name: "testUser")
}
}
@brampat
Copy link

brampat commented Oct 15, 2018

Are your I*Repo's JpaRepository extended interfaces?
I'm struggling to get Unroll'd tests running with properly wired Spring Interface-beans.
Could you help me out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment