久久久久久久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'>

                          • 主站蜘蛛池模板: 国内精品久久久久久影视8 最新黄色在线观看 | 亚洲一区二区在线视频 | 国产成人精品一区二区三区四区 | 欧美日韩精品在线免费观看 | 99国产精品视频免费观看一公开 | 日韩视频精品在线 | 国产区高清 | 伊人伊成久久人综合网站 | 自拍第1页| 亚洲男人的天堂网站 | 欧美一区二区三区,视频 | 国产精品国产三级国产播12软件 | 久久精品这里 | 国产精品久久久久久久久久久久 | 中国一级特黄真人毛片免费观看 | 久久y | 国产第一区二区 | 综合久久综合久久 | 高清一区二区三区 | 中文字幕一区在线观看视频 | 亚洲视频三 | 欧美中文字幕一区二区三区亚洲 | 成人欧美一区二区三区白人 | 色眯眯视频在线观看 | 欧美一a | 亚洲精品永久免费 | 国产精品网址 | 青青久在线视频 | 国内精品视频在线观看 | 亚洲一区二区国产 | 日韩电影免费在线观看中文字幕 | 五月婷婷中文 | 成人福利在线 | 亚洲一区二区中文字幕在线观看 | 欧美2区| av在线影院 | www.788.com色淫免费 | 国产美女视频一区 | 欧美一页 | 91精品国产综合久久香蕉922 | www.日韩免费 |