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

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

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

        Mockito - 预期 0 个匹配器,记录 1 个(InvalidUseOfMa

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

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

        1. <tfoot id='JpR8K'></tfoot>
            <tbody id='JpR8K'></tbody>
        2. <legend id='JpR8K'><style id='JpR8K'><dir id='JpR8K'><q id='JpR8K'></q></dir></style></legend>

              <bdo id='JpR8K'></bdo><ul id='JpR8K'></ul>
                1. 本文介绍了Mockito - 预期 0 个匹配器,记录 1 个(InvalidUseOfMatchersException)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试模拟一些 mongo 类,以便不需要连接(相当标准的东西),但以下代码给我带来了问题:

                  I'm trying to mock up some mongo classes so that I don't need a connection (fairly standard stuff) but the following code gives me problems:

                  when(dbCollection.find(isA(DBObject.class))).thenReturn(dbCursor);
                  

                  运行这个得到我:

                  org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
                  参数匹配器的使用无效!
                  预期 0 个匹配器,记录 1 个:
                  在 ...GridFileManagerTest.beforeClass(GridFileManagerTest.java:67)

                  org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
                  Invalid use of argument matchers!
                  0 matchers expected, 1 recorded:
                  at ...GridFileManagerTest.beforeClass(GridFileManagerTest.java:67)

                  如果匹配器与原始值组合,则可能会发生此异常:
                  //不正确:someMethod(anyObject(), "raw String");

                  This exception may occur if matchers are combined with raw values:
                  //incorrect: someMethod(anyObject(), "raw String");

                  使用匹配器时,所有参数都必须由匹配器提供.
                  例如:
                  //正确:
                  someMethod(anyObject(), eq("String by matcher"));

                  When using matchers, all arguments have to be provided by matchers.
                  For example:
                  //correct:
                  someMethod(anyObject(), eq("String by matcher"));

                  有关更多信息,请参阅 Matchers 类的 javadoc.

                  For more info see javadoc for Matchers class.

                  如果我这样做:

                  when(dbCollection.find(mock(DBObject.class))).thenReturn(dbCursor);
                  

                  它不再有这个问题.这似乎并没有完成我想要的 - 我想在使用 DBObject 类型的对象调用该方法时返回该值.

                  it no longer has that problem. This doesn't seem to accomplish what I want though - I want to return the value when the method is called with an object of type DBObject.

                  想法?

                  推荐答案

                  我认为你的结果与如果 dbCollection 不是 Mockito-mock (或者你的方法是静态的)会发生的结果兼容或最终).这意味着在无法使用匹配器的地方使用匹配器;因此预期 0 个匹配器,记录 1 个".

                  I think your results are compatible with the result that would happen if dbCollection is not a Mockito-mock (or your method is static or final). That would mean that a matcher is being used where none can be used; hence the "0 matchers expected, 1 recorded".

                  这篇关于Mockito - 预期 0 个匹配器,记录 1 个(InvalidUseOfMatchersException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:SecurityManager 的 Mockito 模拟抛出异常 下一篇:如何更改 Mockito 中字符串的默认返回值?

                  相关文章

                  最新文章

                  <tfoot id='tEkp0'></tfoot>

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

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

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