久久久久久久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 創建一個模擬列表

        Create a mocked list by mockito(通過 mockito 創建一個模擬列表)
            <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 創建一個模擬列表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想創建一個模擬列表來測試以下代碼:

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

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

                  這是我的實現:

                  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 循環中循環 以了解如何執行此操作.

                  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.當您調用 when 并提供您嘗試存根的方法調用時,您在 Mockito 或 PowerMock 中所做的下一件事就是指定調用該方法時會發生什么 - 也就是說,執行 thenReturn 部分.每次對 when 的調用必須跟一個且只有一個對 thenReturn 的調用,然后再對 when 進行任何調用.您對 when 進行了兩次調用而沒有調用 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 創建一個模擬列表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  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>

                            主站蜘蛛池模板: 亚洲成av人片在线观看 | 欧美日韩国产综合在线 | 中文字幕亚洲一区二区三区 | 全免费a级毛片免费看视频免费下 | 自拍偷拍欧美 | 精品一区二区三 | 天天曰天天干 | 在线播放国产一区二区三区 | 91色站 | 欧美亚洲日本 | 黄色在线免费播放 | 91精品久久久久 | 免费色网址 | www.99精品| 一区二区中文字幕 | 精品一区国产 | 一区二区三区在线看 | 亚洲成人免费视频在线观看 | 精品国产精品一区二区夜夜嗨 | 国产一级片免费视频 | 欧美高清视频一区 | 亚洲成人99 | 一区二区三区在线免费 | 四虎免费视频 | 中文字幕亚洲一区二区三区 | 国产精品久久久久一区二区三区 | 久久久久久久一区二区三区 | 日韩免费中文字幕 | 一级片aaa| 精品国产欧美 | 日韩欧美成人一区二区三区 | 女同videos另类 | 欧美精品一区二区三区在线 | av久久 | 亚洲精品aⅴ | 午夜网| 国产精品久久久久一区二区三区 | 成人午夜在线 | 怡红院怡春院一级毛片 | 久久国产区 | 女同久久另类99精品国产 |