admin管理员组文章数量:1391964
I have a class Foo
with generics. Inside class Foo
, I have an interface declared Bar
.
public class Foo<T,U> {
@Autowired
private Bar<T, U> bar;
public Mono<F> calculate(Supplier<Mono<Req<T, U>>> supplier) {
// Trying to invoke a method on bar but bar is coming as null
}
}
@RunWith(.mockito.junit.MockitoJUnitRunner.class)
class FooTest {
@InjectMocks
Foo<classA, classB> foo;
@Mock
private Bar<ClassC, ClassD> bar;
// Method under test is calculate
}
I have tried adding mock name, in setup. I am also initializing mocks, but when I invoke that method.
MockitoAnnotations.initMocks(this);
I am getting the following error:
java.lang.AssertionError: expectation "expectComplete" failed (expected: onComplete(); actual: onError(java.lang.NullPointerException: Cannot invoke "foo.bar(Object, boolean)" because "parameter1" is null))
本文标签: junit5Junit issue mocking an implemetation classStack Overflow
版权声明:本文标题:junit5 - Junit issue mocking an implemetation class - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744607441a2615441.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论