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

    • <bdo id='a162W'></bdo><ul id='a162W'></ul>

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

    1. <tfoot id='a162W'></tfoot>

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

      1. 通過 mockito 創(chuàng)建一個模擬列表

        Create a mocked list by mockito(通過 mockito 創(chuàng)建一個模擬列表)
            <bdo id='Ee1OR'></bdo><ul id='Ee1OR'></ul>

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

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

                  本文介紹了通過 mockito 創(chuàng)建一個模擬列表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想創(chuàng)建一個模擬列表來測試以下代碼:

                  I want to create a mocked list to test below code:

                   for (String history : list) {
                          //code here
                      }
                  

                  這是我的實現(xiàn):

                  public static List<String> createList(List<String> mockedList) {
                  
                      List<String> list = mock(List.class);
                      Iterator<String> iterHistory = mock(Iterator.class);
                  
                      OngoingStubbing<Boolean> osBoolean = when(iterHistory.hasNext());
                      OngoingStubbing<String> osHistory = when(iterHistory.next());
                  
                      for (String history : mockedList) {
                  
                          osBoolean = osBoolean.thenReturn(true);
                          osHistory = osHistory.thenReturn(history);
                      }
                      osBoolean = osBoolean.thenReturn(false);
                  
                      when(list.iterator()).thenReturn(iterHistory);
                  
                      return list;
                  }
                  

                  但是當測試運行時,它會在以下行拋出異常:

                  But when the test run it throw exception at line:

                  OngoingStubbing<DyActionHistory> osHistory = when(iterHistory.next());
                  

                  詳情:

                  org.mockito.exceptions.misusing.UnfinishedStubbingException: 
                  Unfinished stubbing detected here:
                  -> at org.powermock.api.mockito.PowerMockito.when(PowerMockito.java:495)
                  
                  E.g. thenReturn() may be missing.
                  Examples of correct stubbing:
                      when(mock.isOk()).thenReturn(true);
                      when(mock.isOk()).thenThrow(exception);
                      doThrow(exception).when(mock).someVoidMethod();
                  Hints:
                   1. missing thenReturn()
                   2. you are trying to stub a final method, you naughty developer!
                  

                  我該如何解決?謝謝

                  推薦答案

                  好吧,這是一件壞事.不要模擬列表;相反,模擬列表中的各個對象.請參閱 Mockito:模擬將在 for 循環(huán)中循環(huán) 以了解如何執(zhí)行此操作.

                  OK, this is a bad thing to be doing. Don't mock a list; instead, mock the individual objects inside the list. See Mockito: mocking an arraylist that will be looped in a for loop for how to do this.

                  另外,您為什么要使用 PowerMock?你似乎沒有做任何需要 PowerMock 的事情.

                  Also, why are you using PowerMock? You don't seem to be doing anything that requires PowerMock.

                  但問題的真正原因是您在完成存根之前在兩個不同的對象上使用了 when.當您調(diào)用 when 并提供您嘗試存根的方法調(diào)用時,您在 Mockito 或 PowerMock 中所做的下一件事就是指定調(diào)用該方法時會發(fā)生什么 - 也就是說,執(zhí)行 thenReturn 部分.每次對 when 的調(diào)用必須跟一個且只有一個對 thenReturn 的調(diào)用,然后再對 when 進行任何調(diào)用.您對 when 進行了兩次調(diào)用而沒有調(diào)用 thenReturn - 這是您的錯誤.

                  But the real cause of your problem is that you are using when on two different objects, before you complete the stubbing. When you call when, and provide the method call that you are trying to stub, then the very next thing you do in either Mockito OR PowerMock is to specify what happens when that method is called - that is, to do the thenReturn part. Each call to when must be followed by one and only one call to thenReturn, before you do any more calls to when. You made two calls to when without calling thenReturn - that's your error.

                  這篇關于通過 mockito 創(chuàng)建一個模擬列表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉換為整數(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 能夠將 0xff000000 存儲為 int?)

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

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

                        <tbody id='yYO3G'></tbody>
                      1. <legend id='yYO3G'><style id='yYO3G'><dir id='yYO3G'><q id='yYO3G'></q></dir></style></legend>

                        • <bdo id='yYO3G'></bdo><ul id='yYO3G'></ul>

                            主站蜘蛛池模板: 欧美中文在线 | 精品综合网 | 欧美日韩综合精品 | 黄网站在线观看 | 狠狠干综合视频 | 久久不卡| 欧美日一区 | 成人国产精品久久久 | 欧美中文字幕在线 | 免费看黄色国产 | jizz在线免费观看 | 日韩三区在线 | 在线免费观看日本 | 天天看天天干 | 久久91av| 中文字幕一区二区三区在线观看 | 亚洲视频二 | 国产成人jvid在线播放 | 久草在线在线精品观看 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 九色91视频 | 国产精品久久久久一区二区 | 国产精品一区二区电影 | 欧美日韩国产一区二区三区 | 久久精品 | 一区二区三区高清不卡 | 一区二区三区欧美 | 亚洲成在线观看 | 久久久久国产一区二区三区四区 | 欧美国产一区二区三区 | 中文字幕男人的天堂 | 久久黄色网 | 亚洲一区在线播放 | 久久中文字幕电影 | 亚洲黄色成人网 | av香蕉 | 亚洲a视频 | 一区二区免费在线视频 | 三级在线免费 | 久久999 | 欧美一区二区三区精品免费 |