<i id='RQbwP'><tr id='RQbwP'><dt id='RQbwP'><q id='RQbwP'><span id='RQbwP'><b id='RQbwP'><form id='RQbwP'><ins id='RQbwP'></ins><ul id='RQbwP'></ul><sub id='RQbwP'></sub></form><legend id='RQbwP'></legend><bdo id='RQbwP'><pre id='RQbwP'><center id='RQbwP'></center></pre></bdo></b><th id='RQbwP'></th></span></q></dt></tr></i><div id='RQbwP'><tfoot id='RQbwP'></tfoot><dl id='RQbwP'><fieldset id='RQbwP'></fieldset></dl></div>
  • <small id='RQbwP'></small><noframes id='RQbwP'>

      • <bdo id='RQbwP'></bdo><ul id='RQbwP'></ul>
      <tfoot id='RQbwP'></tfoot>
      1. <legend id='RQbwP'><style id='RQbwP'><dir id='RQbwP'><q id='RQbwP'></q></dir></style></legend>

        Mockito 可以捕获多次调用的方法的参数吗?

        时间:2023-09-26
        1. <i id='gV9tr'><tr id='gV9tr'><dt id='gV9tr'><q id='gV9tr'><span id='gV9tr'><b id='gV9tr'><form id='gV9tr'><ins id='gV9tr'></ins><ul id='gV9tr'></ul><sub id='gV9tr'></sub></form><legend id='gV9tr'></legend><bdo id='gV9tr'><pre id='gV9tr'><center id='gV9tr'></center></pre></bdo></b><th id='gV9tr'></th></span></q></dt></tr></i><div id='gV9tr'><tfoot id='gV9tr'></tfoot><dl id='gV9tr'><fieldset id='gV9tr'></fieldset></dl></div>

            <tfoot id='gV9tr'></tfoot>
            <legend id='gV9tr'><style id='gV9tr'><dir id='gV9tr'><q id='gV9tr'></q></dir></style></legend>
              <bdo id='gV9tr'></bdo><ul id='gV9tr'></ul>

              <small id='gV9tr'></small><noframes id='gV9tr'>

                <tbody id='gV9tr'></tbody>

                  本文介绍了Mockito 可以捕获多次调用的方法的参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个被调用两次的方法,我想捕获第二个方法调用的参数.

                  I have a method that gets called twice, and I want to capture the argument of the second method call.

                  这是我尝试过的:

                  ArgumentCaptor<Foo> firstFooCaptor = ArgumentCaptor.forClass(Foo.class);
                  ArgumentCaptor<Foo> secondFooCaptor = ArgumentCaptor.forClass(Foo.class);
                  verify(mockBar).doSomething(firstFooCaptor.capture());
                  verify(mockBar).doSomething(secondFooCaptor.capture());
                  // then do some assertions on secondFooCaptor.getValue()
                  

                  但是我得到一个 TooManyActualInvocations 异常,因为 Mockito 认为 doSomething 应该只被调用一次.

                  But I get a TooManyActualInvocations Exception, as Mockito thinks that doSomething should only be called once.

                  如何验证 doSomething 的第二次调用的参数?

                  How can I verify the argument of the second call of doSomething?

                  推荐答案

                  我觉得应该是

                  verify(mockBar, times(2)).doSomething(...)
                  

                  来自 mockito javadoc 的示例:

                  ArgumentCaptor<Person> peopleCaptor = ArgumentCaptor.forClass(Person.class);
                  verify(mock, times(2)).doSomething(peopleCaptor.capture());
                  
                  List<Person> capturedPeople = peopleCaptor.getAllValues();
                  assertEquals("John", capturedPeople.get(0).getName());
                  assertEquals("Jane", capturedPeople.get(1).getName());
                  

                  这篇关于Mockito 可以捕获多次调用的方法的参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:JDK16 和 Mac OS 上的 Mockito - 无法初始化插件 下一篇:Spark:JavaRDD&lt;Tuple2&gt;到 JavaPairRDD&lt;&am

                  相关文章

                  最新文章

                  <tfoot id='7MRfZ'></tfoot>
                    <bdo id='7MRfZ'></bdo><ul id='7MRfZ'></ul>

                    1. <legend id='7MRfZ'><style id='7MRfZ'><dir id='7MRfZ'><q id='7MRfZ'></q></dir></style></legend>

                    2. <i id='7MRfZ'><tr id='7MRfZ'><dt id='7MRfZ'><q id='7MRfZ'><span id='7MRfZ'><b id='7MRfZ'><form id='7MRfZ'><ins id='7MRfZ'></ins><ul id='7MRfZ'></ul><sub id='7MRfZ'></sub></form><legend id='7MRfZ'></legend><bdo id='7MRfZ'><pre id='7MRfZ'><center id='7MRfZ'></center></pre></bdo></b><th id='7MRfZ'></th></span></q></dt></tr></i><div id='7MRfZ'><tfoot id='7MRfZ'></tfoot><dl id='7MRfZ'><fieldset id='7MRfZ'></fieldset></dl></div>

                      <small id='7MRfZ'></small><noframes id='7MRfZ'>