我想测试一个本身引用LiveRelationshipManager的服务:
@Reference
private LiveRelationshipManager liveRelationshipManager;LiveRelationshipManager的实现是隐藏的,我只有api。我如何在我的aemContext中注册它,比如我自己的LanaguageService:
aemContext.registerInjectActivateService(new LanguageService());我发现的一个解决方案是自己创建一个模拟类:
@Component(service = LiveRelationshipManager.class)
public class MockLiveRelationshipManager implements LiveRelationshipManager {但是,如何防止它在我的实际应用程序中被使用,并且只在我的单元测试中使用?还是有更好的方法?
提前感谢!
发布于 2018-02-22 07:59:47
如果只想在测试中使用模拟类,那么应该使用,而不是,用@Component注释它。只需创建模拟实现,然后使用
context.registerService(LiveRelationshipManager.class, new MockLiveRelationshipManager())将其添加到上下文中。
https://stackoverflow.com/questions/48907095
复制相似问题