Created
January 12, 2018 13:22
-
-
Save OsaSoft/a2e1ea62f5fc58aec3988e2b8af8bda9 to your computer and use it in GitHub Desktop.
Spock Spring workaround to using injected Spring beans in Where block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?