测试用例涵盖了预期的数千个对象的创建时间

时间:2019-09-23 10:07:01

标签: spring-webflux jmockit spring-boot-test

被测试覆盖了一段棘手的代码,只看一下方法:

   public Flux<Foo> collect(FooQuery query, Integer elementsCount) {
        var foosFlux = fooRepository.findByFooQuery(query)
                                            .cache();

        return foosFlux.concatWith(foosFlux.count()
                                                   .map(Long::intValue)
                                                   .map(count -> count + elementsCount)
                                                   .filter(count -> count < MAX_EXPORT_FOOS) // constant MAX_EXPORT_FOOS = 100000
                                                   .flatMapMany(count -> collect(query.withDate(query.getDate().plusDays(1)), count)));
    }

如何才能通过测试覆盖MAX_EXPORT_FOOS何时到达的情况?

测试:

  @Test
    public void testCollect() {
        var query = fooQuery();

        new Expectations() {{
            fooRepository.findByFooQuery(query);
            result = Flux.just(....); // Here I need to have more that 100000 Foos
        }};

        StepVerifier.create(subject.export(query))
                    .expectNext(...) // Here I should expect <= 100000 Foos, just because after collect(...) method I call take(MAX_EXPORT_FOOS) method
                    .verifyComplete();
    }

0 个答案:

没有答案