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

        調(diào)用未存根的方法時拋出 RuntimeException

        Throw a RuntimeException when invoking an unstubbed method(調(diào)用未存根的方法時拋出 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>
                  本文介紹了調(diào)用未存根的方法時拋出 RuntimeException的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 Mockito.我想在調(diào)用未存根的方法時拋出 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 之前調(diào)用(mockito when() 調(diào)用如何工作?),它會在之前拋出 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.

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

                          • 主站蜘蛛池模板: 日韩无| 日日久| 久久成人一区 | 超碰在线国产 | 91aiai| 6996成人影院网在线播放 | 麻豆精品久久久 | 国产午夜精品视频 | 亚洲成av人片在线观看无码 | 亚洲精品在线国产 | 午夜男人天堂 | 日韩av免费在线观看 | 日本中文在线视频 | 中文在线一区二区 | 农村妇女毛片精品久久久 | 伊人狠狠操 | 亚洲人人舔人人 | 五月婷婷在线视频 | 国产激情视频在线免费观看 | 婷婷丁香综合网 | 精精国产xxxx视频在线播放7 | 综合久久一区 | 欧美一区二区三区在线观看 | 欧美日批 | 日本精品视频一区二区 | 二区在线视频 | 久久精品成人 | 日韩欧美综合在线视频 | 国产蜜臀97一区二区三区 | 97视频人人澡人人爽 | 一级片免费网站 | 久久精品青青大伊人av | 久久精品亚洲 | 精品免费视频 | 精品视频免费 | 久久精品 | 一级毛片免费完整视频 | 一级在线免费观看 | 精品视频一区二区三区在线观看 | 成人区一区二区三区 | 国产精品3区 |