久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='Isb4a'></small><noframes id='Isb4a'>

      <i id='Isb4a'><tr id='Isb4a'><dt id='Isb4a'><q id='Isb4a'><span id='Isb4a'><b id='Isb4a'><form id='Isb4a'><ins id='Isb4a'></ins><ul id='Isb4a'></ul><sub id='Isb4a'></sub></form><legend id='Isb4a'></legend><bdo id='Isb4a'><pre id='Isb4a'><center id='Isb4a'></center></pre></bdo></b><th id='Isb4a'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Isb4a'><tfoot id='Isb4a'></tfoot><dl id='Isb4a'><fieldset id='Isb4a'></fieldset></dl></div>
      <legend id='Isb4a'><style id='Isb4a'><dir id='Isb4a'><q id='Isb4a'></q></dir></style></legend>
        • <bdo id='Isb4a'></bdo><ul id='Isb4a'></ul>

        <tfoot id='Isb4a'></tfoot>
      1. Mockito 和 Hamcrest:如何驗(yàn)證 Collection 參數(shù)的調(diào)用?

        Mockito and Hamcrest: how to verify invocation of Collection argument?(Mockito 和 Hamcrest:如何驗(yàn)證 Collection 參數(shù)的調(diào)用?)
                <bdo id='TPxNZ'></bdo><ul id='TPxNZ'></ul>
              • <legend id='TPxNZ'><style id='TPxNZ'><dir id='TPxNZ'><q id='TPxNZ'></q></dir></style></legend>

                  <tbody id='TPxNZ'></tbody>
                1. <i id='TPxNZ'><tr id='TPxNZ'><dt id='TPxNZ'><q id='TPxNZ'><span id='TPxNZ'><b id='TPxNZ'><form id='TPxNZ'><ins id='TPxNZ'></ins><ul id='TPxNZ'></ul><sub id='TPxNZ'></sub></form><legend id='TPxNZ'></legend><bdo id='TPxNZ'><pre id='TPxNZ'><center id='TPxNZ'></center></pre></bdo></b><th id='TPxNZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TPxNZ'><tfoot id='TPxNZ'></tfoot><dl id='TPxNZ'><fieldset id='TPxNZ'></fieldset></dl></div>
                2. <tfoot id='TPxNZ'></tfoot>

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

                  本文介紹了Mockito 和 Hamcrest:如何驗(yàn)證 Collection 參數(shù)的調(diào)用?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我遇到了 Mockito 和 Hamcrest 的泛型問(wèn)題.

                  I'm running into a generics problem with Mockito and Hamcrest.

                  請(qǐng)假設(shè)如下界面:

                  public interface Service {
                      void perform(Collection<String> elements);
                  }
                  

                  還有下面的測(cè)試片段:

                  Service service = mock(Service.class);
                  
                  // ... perform business logic
                  
                  verify(service).perform(Matchers.argThat(contains("a", "b")));
                  

                  所以我想驗(yàn)證我的業(yè)務(wù)邏輯是否真的使用包含a"和b"的集合來(lái)調(diào)用服務(wù).

                  So I want to verify that my business logic actually called the service with a collection that contains "a" and "b" in that order.

                  但是contains(...)的返回類型是Matcher,所以 Matchers.argThat(...) 在我的情況下返回 Iterable<String> ,這自然不適用于所需集合.

                  However, the return type of contains(...) is Matcher<Iterable<? extends E>>, so Matchers.argThat(...) returns Iterable<String> in my case, which naturally does not apply to the required Collection<String>.

                  我知道我可以使用 Hamcrest hasItem and Mockito verify 中建議的參數(shù)捕獲器不一致,但我非常不想這樣做.

                  I know that I could use an argument captor as proposed in Hamcrest hasItem and Mockito verify inconsistency, but I would very much like not to.

                  任何建議!謝謝!

                  推薦答案

                  你可以寫(xiě)

                  verify(service).perform((Collection<String>) Matchers.argThat(contains("a", "b")));
                  

                  從編譯器的角度來(lái)看,這是將 Iterable<String> 轉(zhuǎn)換為 Collection 這很好,因?yàn)楹笳呤乔叭蔚?在運(yùn)行時(shí),argThat 將返回 null,因此可以在沒(méi)有 ClassCastException 的情況下將其傳遞給 perform.重要的一點(diǎn)是,匹配器進(jìn)入 Mockito 的內(nèi)部參數(shù)結(jié)構(gòu)進(jìn)行驗(yàn)證,這就是 argThat 所做的.

                  From the compiler's point of view, this is casting an Iterable<String> to a Collection<String> which is fine, because the latter is a subtype of the former. At run time, argThat will return null, so that can be passed to perform without a ClassCastException. The important point about it is that the matcher gets onto Mockito's internal structure of arguments for verification, which is what argThat does.

                  這篇關(guān)于Mockito 和 Hamcrest:如何驗(yàn)證 Collection 參數(shù)的調(diào)用?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測(cè) 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語(yǔ)句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)
                  <tfoot id='U4ZF5'></tfoot>

                    <bdo id='U4ZF5'></bdo><ul id='U4ZF5'></ul>

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

                      <legend id='U4ZF5'><style id='U4ZF5'><dir id='U4ZF5'><q id='U4ZF5'></q></dir></style></legend>
                        • <i id='U4ZF5'><tr id='U4ZF5'><dt id='U4ZF5'><q id='U4ZF5'><span id='U4ZF5'><b id='U4ZF5'><form id='U4ZF5'><ins id='U4ZF5'></ins><ul id='U4ZF5'></ul><sub id='U4ZF5'></sub></form><legend id='U4ZF5'></legend><bdo id='U4ZF5'><pre id='U4ZF5'><center id='U4ZF5'></center></pre></bdo></b><th id='U4ZF5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='U4ZF5'><tfoot id='U4ZF5'></tfoot><dl id='U4ZF5'><fieldset id='U4ZF5'></fieldset></dl></div>
                              <tbody id='U4ZF5'></tbody>

                            主站蜘蛛池模板: 成人免费一区二区三区视频网站 | 国产男人的天堂 | 久久久久9999 | 荷兰欧美一级毛片 | 久久精品国产清自在天天线 | 成人精品一区亚洲午夜久久久 | 精品一区二区三区日本 | 欧美一区二区三区视频在线播放 | 亚洲国产免费 | 久久精品成人一区 | 一级毛片大全免费播放 | 成人激情视频免费在线观看 | 欧美综合一区 | 亚洲黄色高清视频 | 91久操视频 | 国产在线精品一区 | 亚洲国产精品99久久久久久久久 | 久久成人国产 | av片在线观看网站 | 在线日韩视频 | 色视频网站免费 | 欧美久久视频 | 一级久久久久久 | 亚洲视频在线看 | 色综合成人网 | 精品久久久久久久久久久久 | 中文字幕一区二区三区四区五区 | 美女一级黄 | 亚洲精品区 | 亚洲一区二区久久 | 天天看片天天干 | 亚洲国产成人久久综合一区,久久久国产99 | 国产高清在线视频 | 国产黄色大片网站 | 羞羞免费网站 | 天天综合日日夜夜 | 一区二区三区视频在线免费观看 | www.国产.com| 国产高清视频 | 国产福利在线播放 | 成人免费小视频 |