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

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

      <tfoot id='3MlQk'></tfoot>

      1. <small id='3MlQk'></small><noframes id='3MlQk'>

      2. Mockito when() 不區(qū)分子類

        Mockito when() doesn#39;t differentiate between child classes(Mockito when() 不區(qū)分子類)
          <bdo id='YHV0i'></bdo><ul id='YHV0i'></ul>

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

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

                • <tfoot id='YHV0i'></tfoot>
                • 本文介紹了Mockito when() 不區(qū)分子類的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我編寫了一個(gè)使用 Mockito 1.9.5 的測(cè)試.我有一個(gè) HttpGet 和一個(gè) HttpPost 其中一個(gè) HttpClient 執(zhí)行,我正在測(cè)試以驗(yàn)證每個(gè)響應(yīng)是否以輸入流的形式返回預(yù)期結(jié)果.

                  I wrote a test that uses Mockito 1.9.5. I have an HttpGet and an HttpPost which an HttpClient execute, and I'm testing to verify that the response from each returns the expected result in the form of an input stream.

                  問題是在使用Mockito.when(mockedClient.execute(any(HttpPost.class))).thenReturn(postResponse)Mockito.when(mockedClient.execute(any(HttpGet.class))).thenReturn(getResponse),其中響應(yīng)是不同的對(duì)象,mockedClient.execute() 總是返回 getResponse.

                  The issue is that while using Mockito.when(mockedClient.execute(any(HttpPost.class))).thenReturn(postResponse) and Mockito.when(mockedClient.execute(any(HttpGet.class))).thenReturn(getResponse), where the responses are different objects, mockedClient.execute() always returns getResponse.

                  我寫的測(cè)試如下:

                  private InputStream       postContent;
                  private InputStream       getContent;
                  @Mock
                  private FilesHandler hand;
                  @Mock
                  private MockHttpClient    client;
                  private MockHttpEntity    postEntity;
                  private MockHttpEntity    getEntity;
                  private MockHttpResponse  postResponse;
                  private MockHttpResponse  getResponse;
                  private String imgQuery = "someQuery";
                  private ParametersHandler ph;
                  private FileHandlerImpl   fileHand;
                  private String            indexFolder = "src/test/resources/misc/";
                  private String            indexFile   = "index.csv";
                  
                  @Before
                  public void setUp() {
                      MockitoAnnotations.initMocks(this);
                      try {
                          postContent = new FileInputStream(indexFolder + "testContent.txt");
                          postEntity = new MockHttpEntity(postContent);
                          postResponse = new MockHttpResponse(postEntity, new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, "postReasonPhrase"));
                          getContent = new FileInputStream(indexFolder + "testContent.txt");
                          getEntity = new MockHttpEntity(getContent);
                          getResponse = new MockHttpResponse(getEntity, new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, "getReasonPhrase"));
                          ph = new ParametersHandler();
                          fileHand = new FileHandlerImpl(client, ph, indexFolder, indexFile);
                      } catch (Exception e) {
                          failTest(e);
                      }
                  }
                  @Test
                  public void getFileWhenEverythingJustWorks() {
                  
                      try {
                          Mockito.when(client.execute(Mockito.any(HttpPost.class))).thenReturn(postResponse);
                          Mockito.when(client.execute(Mockito.any(HttpGet.class))).thenReturn(getResponse);
                          fileHand.getFile(hand, imgQuery, ph, "I");
                          Mockito.verify(hand).rebuildIndex(Mockito.any(String.class), Mockito.any(Map.class), Mockito.any(Map.class), hand);
                      } catch (IOException e) {
                          failTest(e);
                      }
                  }
                  

                  正在測(cè)試的方法的簡(jiǎn)化版本如下.

                  A shortened version of the method being tested is below.

                  public void getFile(FilesHandler fileHandlerFl, String query, ParametersHandler ph, String type) {
                  
                          JsonFactory factory = new JsonFactory();
                          HttpPost post = preparePost(query, factory);
                          CloseableHttpResponse response = client.execute(post);
                  
                      String uri = "https://someuri.com" + "/File";
                          HttpGet get = new HttpGet(uri);
                          setParameters(get);
                          response.close();
                          response = client.execute(get);
                  }
                  

                  一如既往,感謝您提供的任何幫助.

                  As always, any help you can provide is appreciated.

                  推薦答案

                  盡管在 Mockito 1.x 中用英語閱讀時(shí)它意味著什么,any(HttpGet.class) 匹配 any value 而不僅僅是 any HttpGet.該參數(shù)僅用于保存 Java 8 之前的強(qiáng)制轉(zhuǎn)換.

                  Despite what it would mean when read in English, in Mockito 1.x, any(HttpGet.class) matches any value and not just any HttpGet. The parameter is only used to save a cast previous to Java 8.

                  來自 Matchers.any(Class) 文檔:

                  匹配任何對(duì)象,包括空值

                  Matches any object, including nulls

                  此方法不對(duì)給定參數(shù)進(jìn)行類型檢查,它只是為了避免在代碼中進(jìn)行強(qiáng)制轉(zhuǎn)換.但是,這可能會(huì)在未來的主要版本中發(fā)生變化(可能會(huì)添加類型檢查).

                  This method doesn't do type checks with the given parameter, it is only there to avoid casting in your code. This might however change (type checks could be added) in a future major release.

                  使用 isA(HttpGet.class)isA(HttpPost.class) 代替,請(qǐng)參閱下面 Brice 關(guān)于 any(Class<?> clazz) 匹配器.

                  Use isA(HttpGet.class) and isA(HttpPost.class) instead, and see Brice's comment below about future changes to the any(Class<?> clazz) matcher.

                  這篇關(guān)于Mockito when() 不區(qū)分子類的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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 語句之前的局部變量,這有關(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?)
                  <legend id='Z2kgr'><style id='Z2kgr'><dir id='Z2kgr'><q id='Z2kgr'></q></dir></style></legend>

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

                      <tbody id='Z2kgr'></tbody>
                      <tfoot id='Z2kgr'></tfoot>
                        <bdo id='Z2kgr'></bdo><ul id='Z2kgr'></ul>

                          1. 主站蜘蛛池模板: 国产成人精品一区二三区在线观看 | 欧美精品91 | 午夜久久av | 国产成人精品久久二区二区91 | 在线观看中文字幕av | 色综合激情 | 精品亚洲一区二区三区 | 亚洲a在线观看 | 激情六月天 | 中文字幕在线观看一区二区 | 久久亚洲一区二区 | 天堂中文在线播放 | 欧美在线一区二区三区 | 国产中文在线 | 91精品国产综合久久婷婷香蕉 | 久久久不卡网国产精品一区 | 国外成人免费视频 | 欧美一级免费看 | 成人在线视频观看 | av色站 | www.久久久久久久久久久久 | 国产亚洲精品久久久优势 | av中文字幕在线 | 男女视频在线免费观看 | 精品99爱视频在线观看 | 国产午夜三级一区二区三 | 国产精品久久亚洲 | 免费观看一级特黄欧美大片 | 九九亚洲 | 特级做a爱片免费69 精品国产鲁一鲁一区二区张丽 | 日本一区不卡 | 国产一区二区三区欧美 | 日韩精品免费看 | 国产激情一区二区三区 | 国产精品久久久亚洲 | 欧美精品乱码久久久久久按摩 | www.婷婷 | www.色五月.com | 亚洲激情在线观看 | 一区二区av| 久久99精品久久久久久琪琪 |