最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

junit5 - Junit issue mocking an implemetation class - Stack Overflow

programmeradmin2浏览0评论

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))

发布评论

评论列表(0)

  1. 暂无评论