最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - MockedConstruction of class with type parameters (type inference?) - Stack Overflow

programmeradmin2浏览0评论

I want to test a method that creates an ArrayList<String>. I want to capture what it puts into the list. How do I create a MockedConstruction<ArrayList<String>>? For example:

try(MockedConstruction<ArrayList<String>> arrayListMockedConstruction = /* what to put here? */)) {

      myClass.myMethod();

      ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.captor();
      when(arrayListMockedConstruction.constructed().add(stringArgumentCaptor.capture())).thenReturn(true);
} catch (Exception e) {
      fail();
}

Isn't there a way to create a mocked construction like with the captor() method for ArgumentCaptor, or maybe an annotation for a field of the test class?

发布评论

评论列表(0)

  1. 暂无评论