为什么我在这里得到InvalidUseOfMatchers构建错误?

时间:2018-03-04 08:07:55

标签: java mockito junit4 matcher

这段代码编译和调试很好,但是当我在Eclipse中进行maven构建时,单元测试和构建失败。我不明白这里滥用匹配器的位置在哪里?感谢。

[错误]错误:[错误] Tests.MyTest()»InvalidUseOfMatchers

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {MapperFactory.class})
public class Tests {
  @Mock private Bucket bucketMock;
  @Mock private MutateInBuilder builderMock;
  @InjectMocks private Repository couchbaseRepository;
  private MapperFactory mapperFactory;

  @Autowired
  public void setMapperFactory(MapperFactory mapperFactory) {
    this.mapperFactory = mapperFactory;
  }
  @Test
  public void MyTest() throws MyException {
    String jsonText = jsonSamples.getProperty("theJson");
    Mapper mapper = mapperFactory.getMapper(JsonObject.fromJson(jsonText),repository);    

   when(bucketMock.mutateIn("1234")).thenReturn(builderMock);
   mapper.execute();
   verify(builderMock).execute();
 }
}

1 个答案:

答案 0 :(得分:0)

感谢你的帮助,这是对的,这就是所有例外。解决方案是在pom.xml文件中更新Mockito的artifactId:

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>1.10.19</version>
</dependency>  

替换为:

 <dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>1.10.19</version>
</dependency>