【发布时间】:2020-09-18 16:15:42
【问题描述】:
我正在尝试为抛出异常但不知何故抛出 null 而不是异常的情况编写单元测试。
我试图模拟的服务调用。
private List<Vertex> getVertexList(final String vertexId, GraphTraversalSource graphTraversalSource, final int indexToLoop) {
return graphTraversalSource.V(vertexId).repeat(in().dedup().simplePath()).until(loops().is(indexToLoop)).toList();
}
我写了以下来模拟抛出异常
@Mock(answer = RETURNS_DEEP_STUBS)
private GraphTraversalSource gts;
Mockito.when(gts.V(anyString()).repeat(any()).until((Predicate<Traverser<Vertex>>) any()).toList()).thenThrow(Exception.class);
有什么方法可以模拟它以抛出异常?提前致谢。
【问题讨论】:
标签: unit-testing junit mockito gremlin