Cannot create mock for LoginService class. CGLIB library is required for bullying types without an interface ..?

Am I using grails 2.4.2 and does it already have spock installed by default? Well, one of my control tests does not work quite right. I try to make fun of a few of my services, but I keep getting this error:

 Failure:  confirmEmailAddress() when verification failed(com.zee.RegistrationControllerSpec)
|  org.spockframework.mock.CannotCreateMockException: Cannot create mock for class com.zee.LoginService. Mocking of non-interface types requires the CGLIB library. Please put cglib-nodep-2.2 or higher on the class path.
    at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:52)
    at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:51)
    at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
    at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:47)
    at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:282)
    at org.spockframework.lang.SpecInternals.MockImpl(SpecInternals.java:83)
    at com.zee.RegistrationControllerSpec.setup(RegistrationControllerSpec.groovy:22)

I could not find anything on the Internet about this. My Spec controller looks like this:

import grails.test.mixin.TestFor
import spock.lang.Specification

@TestFor(RegistrationController)
class RegistrationControllerSpec extends Specification {

    LoginService loginService

    EmailAddressConfirmationService emailAddressConfirmationService

    EmailNotificationService emailNotificationService

    AccountRecordService accountRecordService

    def setup() {
        loginService = Mock()
        emailAddressConfirmationService = Mock()
        emailNotificationService = Mock()
        accountRecordService = Mock()

        controller.loginService = loginService
        controller.emailAddressConfirmationService = emailAddressConfirmationService
        controller.emailNotificationService = emailNotificationService
        controller.accountRecordService = accountRecordService
    }

    def cleanup() {
    }

    void "confirmEmailAddress() when verification failed"() {
        // some test here....
    }
}

My service is even simpler:

import grails.transaction.Transactional

@Transactional
class LoginService {

    def registerUser(Login login) {
        login.pincode = "";
        login.groupId = Login.REGISTERED_USER_GROUP_ID
        login.save(flush :true)
    }

    public void userJoined(Login login) {
        login.save(flush: true)
    }
}

I stamped. Even pure graals will not do the trick. Any help? D:

+4
source share
1 answer

In buildConfig.groovy Replace this line: ':cache:1.1.7'with ':cache:1.1.6' For example:

plugins {
         compile ':cache:1.1.6'
}

, cglib- . .

: cache:1.1.7, cglib buildConfig.groovy :

dependencies { 
        compile 'org.objenesis:objenesis:1.4'
        compile "cglib:cglib:2.2"
}
plugins {
             compile ':cache:1.1.7'
}
+16

All Articles