pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="822q17g" 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="cufgu8z" 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ū)分子類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我編寫了一個使用 Mockito 1.9.5 的測試.我有一個 HttpGet 和一個 HttpPost 其中一個 HttpClient 執(zhí)行,我正在測試以驗證每個響應是否以輸入流的形式返回預期結(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),其中響應是不同的對象,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.

                  我寫的測試如下:

                  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);
                      }
                  }
                  

                  正在測試的方法的簡化版本如下.

                  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 中用英語閱讀時它意味著什么,any(HttpGet.class) 匹配 any value 而不僅僅是 any HttpGet.該參數(shù)僅用于保存 Java 8 之前的強制轉(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) 文檔:

                  匹配任何對象,包括空值

                  Matches any object, including nulls

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

                  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) 代替,請參閱下面 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ū)分子類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 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)建一個隨機打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲為 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="mfwrvlv" 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. 主站蜘蛛池模板: 产业规划_产业园区规划-产业投资选址及规划招商托管一体化服务商-中机院产业园区规划网 | 天津电机维修|水泵维修-天津晟佳机电设备有限公司 | 珠光砂保温板-一体化保温板-有釉面发泡陶瓷保温板-杭州一体化建筑材料 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 电竞学校_电子竞技培训学校学院-梦竞未来电竞学校官网 | 拖鞋定制厂家-品牌拖鞋代加工厂-振扬实业中国高端拖鞋大型制造商 | 无锡网站建设-做网站-建网站-网页设计制作-阿凡达建站公司 | 阀门智能定位器_电液动执行器_气动执行机构-赫尔法流体技术(北京)有限公司 | 换网器_自动换网器_液压换网器--郑州海科熔体泵有限公司 | 工装定制/做厂家/公司_工装订做/制价格/费用-北京圣达信工装 | [品牌官网]贵州遵义双宁口腔连锁_贵州遵义牙科医院哪家好_种植牙_牙齿矫正_原华美口腔 | 全自动包装秤_全自动上袋机_全自动套袋机_高位码垛机_全自动包装码垛系统生产线-三维汉界机器(山东)股份有限公司 | 垃圾压缩设备_垃圾处理设备_智能移动式垃圾压缩设备--山东明莱环保设备有限公司 | 彭世修脚_修脚加盟_彭世修脚加盟_彭世足疗加盟_足疗加盟连锁_彭世修脚技术培训_彭世足疗 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 手机游戏_热门软件app下载_好玩的安卓游戏下载基地-吾爱下载站 | 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 车充外壳,车载充电器外壳,车载点烟器外壳,点烟器连接头,旅行充充电器外壳,手机充电器外壳,深圳市华科达塑胶五金有限公司 | 热镀锌槽钢|角钢|工字钢|圆钢|H型钢|扁钢|花纹板-天津千百顺钢铁贸易有限公司 | 假肢-假肢价格-假肢厂家-河南假肢-郑州市力康假肢矫形器有限公司 | 制氮设备-变压吸附制氮设备-制氧设备-杭州聚贤气体设备制造有限公司 | 乙炔气体报警装置|固定式氯化氢检测仪|河南驰诚电气百科 | 碳纤维复合材料制品生产定制工厂订制厂家-凯夫拉凯芙拉碳纤维手机壳套-碳纤维雪茄盒外壳套-深圳市润大世纪新材料科技有限公司 | 汽液过滤网厂家_安平县银锐丝网有限公司 | 不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰]-不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰] | 高低温老化试验机-步入式/低温恒温恒湿试验机-百科 | 工业硝酸钠,硝酸钠厂家-淄博「文海工贸」 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 | 卓能JOINTLEAN端子连接器厂家-专业提供PCB接线端子|轨道式端子|重载连接器|欧式连接器等电气连接产品和服务 | 仿真植物|仿真树|仿真花|假树|植物墙 - 广州天昆仿真植物有限公司 | 钢制拖链生产厂家-全封闭钢制拖链-能源钢铝拖链-工程塑料拖链-河北汉洋机械制造有限公司 | 彼得逊采泥器-定深式采泥器-电动土壤采样器-土壤样品风干机-常州索奥仪器制造有限公司 | 礼至家居-全屋定制家具_一站式全屋整装_免费量房设计报价 | 水压力传感器_数字压力传感器|佛山一众传感仪器有限公司|首页 | 螺旋丝杆升降机-SWL蜗轮-滚珠丝杆升降机厂家-山东明泰传动机械有限公司 | 滚筒线,链板线,总装线,流水线-上海体能机电有限公司 | 等离子表面处理机-等离子表面活化机-真空等离子清洗机-深圳市东信高科自动化设备有限公司 | 昆明挖掘机修理厂_挖掘机翻新再制造-昆明聚力工程机械维修有限公司 | 臭氧发生器_臭氧消毒机 - 【同林品牌 实力厂家】 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 |