我有这条路线:
public class SomeRoute {
@OVerride
public void configure() {
from("direct:route1")
.process(processor1)
.split(body())
.process(persistProcessor)
....
}
}
为此测试类:
public class SOmeRouteTest {
Processor processor1Mock;
@Before
public void setUp() {
processor1Mock = Mockito.mock(Processor1.class);
testObj = new SomeRoute();
testObj.setProcessor1(processor1Mock);
}
@TEst
public void test() {
//Processor processor = MOckito.mock(Processor1.class);
doAnswer((Answer) invocation -> {
// something with Exchange
Exchange ex = invocation.getARgumentAt(0, Exchange.class);
ex.getIn().setBody(new ArrayList<String>);
return null;
})
template.sendBody("route1", json);
}
}
。 现在,拆分不起作用,它直接进入persistProcessor。实际的Processor1正在生成类强制转换异常,因为persistProcessor期望使用String,但是路由将其传递给ArrayList。
请帮助。