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

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

          <bdo id='Jsd5h'></bdo><ul id='Jsd5h'></ul>
      1. <tfoot id='Jsd5h'></tfoot>

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

        調用未存根的方法時拋出 RuntimeException

        Throw a RuntimeException when invoking an unstubbed method(調用未存根的方法時拋出 RuntimeException)

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

            <bdo id='bHnc3'></bdo><ul id='bHnc3'></ul>
          • <tfoot id='bHnc3'></tfoot>

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

                    <tbody id='bHnc3'></tbody>
                  本文介紹了調用未存根的方法時拋出 RuntimeException的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 Mockito.我想在調用未存根的方法時拋出 RuntimeException.

                  I'm using Mockito. I want to throw a RuntimeException when an unstubbed method is called.

                  有什么辦法嗎?

                  推薦答案

                  您可以為模擬設置默認答案.所有未存根的方法都將使用此默認答案.

                  You can set a default answer for a mock. All methods that aren't stubbed will use this default answer.

                  public void testUnstubbedException() {
                      // Create a mock with all methods throwing a RuntimeException by default
                      SomeClass someClass = mock( SomeClass .class, new RuntimeExceptionAnswer() );
                  
                      doReturn(1).when(someClass).getId(); // Must use doReturn
                  
                      int id = someClass.getId(); // Will return 1
                  
                      someClass.unstubbedMethod(); // Will throw RuntimeException
                  }
                  
                  public static class RuntimeExceptionAnswer implements Answer<Object> {
                  
                      public Object answer( InvocationOnMock invocation ) throws Throwable {
                          throw new RuntimeException ( invocation.getMethod().getName() + " is not stubbed" );
                      }
                  
                  }
                  

                  請注意,您不能when 與此功能一起使用,因為該方法在 when 之前調用(mockito when() 調用如何工作?),它會在之前拋出 RuntimeException模擬進入存根模式.

                  Note that you cannot use when with this functionality, since the method is called before when (How does mockito when() invocation work?) and it will throw a RuntimeException before the mock goes into stubbing mode.

                  因此,您必須使用 doReturn 才能使其工作.

                  Therefore, you must use doReturn for this to work.

                  這篇關于調用未存根的方法時拋出 RuntimeException的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                    <tbody id='uSsQU'></tbody>

                      <legend id='uSsQU'><style id='uSsQU'><dir id='uSsQU'><q id='uSsQU'></q></dir></style></legend>

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

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

                          • 主站蜘蛛池模板: 香蕉看片 | 精品少妇av| 自拍三区 | 懂色av懂色av粉嫩av | 国产一区二区观看 | 久久精品国产亚洲 | 亚洲欧美日韩综合 | 99久久精品国产毛片 | 亚洲男人的天堂在线观看 | 中文字幕不卡在线观看 | 国产无遮挡又黄又爽又色 | 91视频色| 人人爽视频 | 国产午夜一区二区三区 | 黄色片免费网站 | 成人毛片在线观看 | 国产日韩精品视频 | 日韩免费小视频 | 日本在线观看网站 | 国产精品一区一区三区 | 国产精品999 | 免费成人毛片 | 久久久久久精 | 天天草天天射 | 在线观看黄色片 | 成人国产精品久久久网站 | 日韩成人三级 | 电家庭影院午夜 | 精品精品| 欧美狠狠操 | 久久免费国产视频 | 成年人免费看片 | 在线观看中文字幕 | 九九热视频在线观看 | 日韩专区在线观看 | 成人国产精品久久久网站 | 国产精品xxx在线观看 | 中文字幕在线观看第一页 | 国产欧美久久久 | 成年免费视频黄网站在线观看 | 蜜桃精品视频 |