久久久久久久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)用未存根的方法時(shí)拋出 RuntimeException

        Throw a RuntimeException when invoking an unstubbed method(調(diào)用未存根的方法時(shí)拋出 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)用未存根的方法時(shí)拋出 RuntimeException的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我正在使用 Mockito.我想在調(diào)用未存根的方法時(shí)拋出 RuntimeException.

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

                  有什么辦法嗎?

                  推薦答案

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

                  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" );
                      }
                  
                  }
                  

                  請(qǐng)注意,您不能when 與此功能一起使用,因?yàn)樵摲椒ㄔ?when 之前調(diào)用(mockito when() 調(diào)用如何工作?),它會(huì)在之前拋出 RuntimeException模擬進(jìn)入存根模式.

                  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.

                  這篇關(guān)于調(diào)用未存根的方法時(shí)拋出 RuntimeException的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測(cè) 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語(yǔ)句之前的局部變量,這有關(guān)系嗎?)
                  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)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 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'>

                          • 主站蜘蛛池模板: 97精品国产97久久久久久免费 | 欧美国产亚洲一区二区 | 久久五月婷 | 成人天堂噜噜噜 | 久久精品一级 | 欧美黑人体内she精在线观看 | 91亚洲视频在线 | 久久久久久久久久久福利观看 | 网站黄色在线 | av午夜电影| 久久久国产一区二区三区 | 亚洲在线高清 | 夜夜夜久久久 | 国产精品日韩欧美一区二区 | 视频在线亚洲 | 欧美a级成人淫片免费看 | 日韩欧美精品在线播放 | 青青草原综合久久大伊人精品 | 日韩中文字幕在线观看视频 | 亚洲精品视频在线观看免费 | 国产精品美女 | 久久国产精品一区二区三区 | 欧洲在线视频 | 一级电影免费看 | 亚洲精品高清视频在线观看 | 久久久久精 | 日韩在线中文字幕 | 中文字幕一区二区三区精彩视频 | 在线播放一区二区三区 | 国产又爽又黄的视频 | 亚洲国内精品 | 一区二区三区亚洲 | 亚洲一区二区久久 | 精品毛片 | 欧美日韩成人一区二区 | 五月免费视频 | 国产在线97| 狠狠色综合久久婷婷 | 羞羞视频在线观免费观看 | 在线一区二区三区 | 久久综合av|