Question

We have Grails 2.2.1 on a project. I want to test a service. In this service I use a dynamicFinder (findAllBy...) but the result of this finder when used in a unit test using domain mocks is an EmptyList. But when I look in UserRole.list() there are 3 UserRoles for the same user. It seems that Domain.findAllBy... is broken in mocked domains.

The Domain class looks like this:

class UserRole implements Serializable {
  User user
  Role role

  static mapping = {
    table      name:      "Sec_User_Sec_Role"
    id         composite: ['role', 'user']
    version    false
  }
}

And the test looks like:

@TestFor(UserService)
@Mock([User, UserRole, Role])
@TestMixin([DomainClassUnitTestMixin])
class UserServiceTests {
  // setup to create User, UserRole and Role
  // test the service
}

And the service looks like:

class UserService {
 ....
   private List<UserRole> findExistingUserRolePairs (final User user) {
      return UserRole.findAllByUser (user)
   }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top