Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于Dubbo接口或Spring动态代理的mock #27

Open
ggggiaqgyd opened this issue Sep 27, 2019 · 1 comment
Open

关于Dubbo接口或Spring动态代理的mock #27

ggggiaqgyd opened this issue Sep 27, 2019 · 1 comment

Comments

@ggggiaqgyd
Copy link

作者您好:JMockit中文网很详细,非常感谢您。最近在项目中遇到一个问题
http://jmockit.cn/showArticle.htm?channel=3&id=28

在使用这个demo进行dubbo接口的Mock
`//dubbo消费bean的MockUp(伪类)
@SuppressWarnings("rawtypes")
public class DubboConsumerBeanMockUp extends MockUp {
// 自定义的消费bean mock对象
private Map<String, Object> mockMap;

public DubboConsumerBeanMockUp() {
}

public DubboConsumerBeanMockUp(Map<String, Object> mockMap) {
    this.mockMap = mockMap;
}

// 对ReferenceBean的getObject方法的Mock
@SuppressWarnings("unchecked")
@Mock
public Object getObject(Invocation inv) throws Exception {
    ReferenceBean ref = inv.getInvokedInstance();
    String interfaceName = ref.getInterface();
    Object mock = mockMap.get(interfaceName);
    if (mock != null) {
        return mock;
    }
    return (new MockUp(Class.forName(interfaceName)) {
    }).getMockInstance();
}

}`
此段代码中的getObject方法不知道什么时候会呗执行

@ggggiaqgyd
Copy link
Author

而且调用的时候,没有成功的Mock掉dubbo接口

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant