Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 类java.util.LinkedList不能强制转换为类org.reactivestreams.Publisher_Spring Boot_Mockito - Fatal编程技术网

Spring boot 类java.util.LinkedList不能强制转换为类org.reactivestreams.Publisher

Spring boot 类java.util.LinkedList不能强制转换为类org.reactivestreams.Publisher,spring-boot,mockito,Spring Boot,Mockito,我正在尝试使用Junit和Mockito创建一个单元测试。然而,我得到了一个错误的说法 class java.util.LinkedList cannot be cast to class org.reactivestreams.Publisher 当调用时,它清楚地返回字符串列表 试验 @测试 public void fullLoad(){ 当((Publisher)this.mockedProductComponent.getErpNumbers(“US”、“es”))。然后返回( jus

我正在尝试使用Junit和Mockito创建一个单元测试。然而,我得到了一个错误的说法

class java.util.LinkedList cannot be cast to class org.reactivestreams.Publisher
当调用时,它清楚地返回字符串列表

试验

@测试
public void fullLoad(){
当((Publisher)this.mockedProductComponent.getErpNumbers(“US”、“es”))。然后返回(
just(新的ArrayList())
);
}
正在测试的方法

public boolean fullLoad(String country, String language) {

        List<String> erpNumbers = productComponent.getErpNumbers(country, language);
        log.info("Retrieved following ERP numbers: {}", erpNumbers);

        Lists.partition(erpNumbers, batchSize)
            .forEach(handleBatch(country, language));
        return true;
    }
public boolean满载(字符串国家/地区、字符串语言){
List-erpNumbers=productComponent.getErpNumbers(国家、语言);
log.info(“检索到以下ERP编号:{}”,ERP编号);
Lists.partition(编号、批次大小)
.forEach(车把套(国家、语言));
返回true;
}
试图模仿的方法

public List<String> getOnlineErpNumbers(String country, String lang) {
        return webClient.get()
            .uri(uriBuilder -> uriBuilder
                .scheme(scheme)
                .host(host)
                .path(path)
                .port(port)
                .pathSegment(country)
                .pathSegment(lang)
                .pathSegment("erp")
                .build())
            .accept(MediaType.APPLICATION_JSON)
            .retrieve()
            .bodyToMono(new ParameterizedTypeReference<List<String>>(){})
            .timeout(Duration.ofMillis(3000))
            .onErrorReturn(Collections.emptyList())
            .block();
    }
公共列表GetOnlinerPerpNumber(字符串国家/地区,字符串语言){
返回webClient.get()
.uri(uriBuilder->uriBuilder
.计划
.主机(主机)
.path(路径)
.港口(港口)
.pathSegment(国家)
.pathSegment(lang)
.pathSegment(“erp”)
.build())
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.BodyToNo(新的参数化类型引用(){})
.超时(持续时间.百万(3000))
.onErrorReturn(Collections.emptyList())
.block();
}

我知道这一定是因为我是以被动的方式进行的,但是我还没有找到关于如何测试这样一个过程的文档。

您混淆了您的导入

您正在使用接受发布服务器的from Reactor:

public static Mono<Void> when(Publisher<?>... sources)
publicstaticmono-when(Publisher…sources)
而不是

publicstaticongoingstublingwhen(T methodCall)

为什么要将结果强制转换为方法返回的(发布者)List@SimonMartinelli这个想法暗示了这一点。没有它,我有一个error@SimonMartinelli当我删除它时,我得到
无法解析方法'when(java.util.List)
为什么返回
just(List)
?您应该在(mockedProductComponent.geterpNumber(“US”、“es”))时执行
,然后返回(Collections.emptyList())
public static Mono<Void> when(Publisher<?>... sources)
public static <T> OngoingStubbing<T> when(T methodCall)