- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 grails 2.4.2,默认情况下它已经安装了 spock 对吗?好吧,我的一个 Controller 测试工作不太正常。我正在尝试模拟我的一些服务,但我不断收到此错误:
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)
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....
}
}
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)
}
}
最佳答案
在您的 buildConfig.groovy
,
替换这一行:':cache:1.1.7'
与 ':cache:1.1.6'
像这样:
plugins {
compile ':cache:1.1.6'
}
cache:1.1.7
您可以在
buildConfig.groovy
中添加 cglib 依赖项像这样:
dependencies {
compile 'org.objenesis:objenesis:1.4'
compile "cglib:cglib:2.2"
}
plugins {
compile ':cache:1.1.7'
}
关于unit-testing - 无法为类 LoginService 创建模拟。非接口(interface)类型的模拟需要 CGLIB 库..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25338200/
Spring不包含cglib依赖,cglib和spring cglib都有Enhancer类,一个是net.sf.cglib.proxy.Enhancer,另一个是org.springframewor
我正在尝试构建一个大型项目,但由于以下错误而失败: [INFO] -------------------------------------------------------------------
关闭。这个问题不符合 Stack Overflow guidelines 。它目前不接受答案。 想改善这个问题吗?更新问题,以便堆栈溢出为 on-topic。 7年前关闭。 Improve this
@Service public class TestService{ @DynamicReference private ITestProvider testProvider;
我有以下通用 cglib 方法拦截器实现: public class EntityInterceptor implements MethodInterceptor{ private Entit
假设我有一些 A 类,它具有 B 类的属性。 public class ClassA{ private ClassB classB; public ClassA(ClassB classB){ th
我正在使用 CGLib 来增强 A 类。 public class A { public void printName(){ System.out.println("guy");
我的 Controller 在其属性上使用了 @Value 注释,但是发生了一些奇怪的事情: 08:20:31.400 [main] ERROR Controller - postConstruct(
我想做的是序列化一个类实现一个命令模式,以便我稍后可以运行它。在最好的在所有世界中,我想序列化一个匿名类(我是意识到这个问题) 让事情变得有点复杂的是我在 Spring 的环境中并且我希望序列化的匿名
谁能给我一个 Java CGLib 的好例子 Mixin类用法?我一直在挖掘它们似乎都不够简单。 最佳答案 很简单: import static org.junit.Assert.*; import
在实际项目中,考虑到不同的数据使用者,我们经常要处理 VO、DTO、Entity、DO 等对象的转换,如果手动编写 setter/getter 方法一个个赋值,将非常繁琐且难维护。通常情况下,这类转换
代码如下: Patient patient = factory.createPatient(); Enhancer enhancer = new Enhancer(
我有两个类 @Component @Scope(proxyMode=ScopedProxyMode.TARGET_CLASS,value="session") public clas
代码是用 Scala 编写的,但希望 Java 程序员也能理解。 我有以下类(class): class SampleClass { def test(in: String) = "Hello w
我无法为 HttpURLConnection 类创建动态代理,因为它没有公共(public)构造函数来创建增强器。根据要求,我想创建一个动态代理以在运行时获取当前连接的详细信息。 我尝试使用this教
我想使用 cglib 作为我的 spring 代理机制。问题是,我有一些 bean 的依赖项由构造函数注入(inject),我无法更改。 CGLIB 似乎不太喜欢这样,不会让我实例化那个 bean。有
当尝试将 CGLIB 与回调过滤器(在数万个对象上)一起使用时,我注意到速度很糟糕,但我无法找到有关优化 CGLIB 的任何信息。 对于搜索/列表界面,系统从优化的查询中加载多个属性,并使用这些属性填
我正在为生产 spring batch 项目构建端到端测试框架。我们想使用内存中的嵌入式数据库(在我们的例子中是 hsqldb)进行这些测试,因为它运行得更快并且没有环境限制。由于这些数据库引擎之间的
借助 cglib,我可以使用以下代码创建延迟实例化的 BigInteger: Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(Bi
我有一个正在开发的 Java 库,它使用 cglib 创建库用户提供的抽象类的子类,并提供自动生成的用户留在其中的抽象方法的实现。 我的问题是,如果有问题的方法具有包本地(即默认)可访问性,我生成的方
我是一名优秀的程序员,十分优秀!