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

    <tfoot id='oVL8n'></tfoot>
  • <small id='oVL8n'></small><noframes id='oVL8n'>

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

          <bdo id='oVL8n'></bdo><ul id='oVL8n'></ul>
        <i id='oVL8n'><tr id='oVL8n'><dt id='oVL8n'><q id='oVL8n'><span id='oVL8n'><b id='oVL8n'><form id='oVL8n'><ins id='oVL8n'></ins><ul id='oVL8n'></ul><sub id='oVL8n'></sub></form><legend id='oVL8n'></legend><bdo id='oVL8n'><pre id='oVL8n'><center id='oVL8n'></center></pre></bdo></b><th id='oVL8n'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oVL8n'><tfoot id='oVL8n'></tfoot><dl id='oVL8n'><fieldset id='oVL8n'></fieldset></dl></div>
      1. 模擬受保護的方法

        mocking protected method(模擬受保護的方法)
          <legend id='HRZrf'><style id='HRZrf'><dir id='HRZrf'><q id='HRZrf'></q></dir></style></legend>
            <i id='HRZrf'><tr id='HRZrf'><dt id='HRZrf'><q id='HRZrf'><span id='HRZrf'><b id='HRZrf'><form id='HRZrf'><ins id='HRZrf'></ins><ul id='HRZrf'></ul><sub id='HRZrf'></sub></form><legend id='HRZrf'></legend><bdo id='HRZrf'><pre id='HRZrf'><center id='HRZrf'></center></pre></bdo></b><th id='HRZrf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HRZrf'><tfoot id='HRZrf'></tfoot><dl id='HRZrf'><fieldset id='HRZrf'></fieldset></dl></div>
          1. <small id='HRZrf'></small><noframes id='HRZrf'>

              <bdo id='HRZrf'></bdo><ul id='HRZrf'></ul>
            • <tfoot id='HRZrf'></tfoot>
                <tbody id='HRZrf'></tbody>

                  本文介紹了模擬受保護的方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想模擬一個繼承的受保護方法.我不能直接從java代碼調用這個方法,因為它是從另一個包中的類繼承的.我找不到在 when(...)

                  I want to mock an inherited protected method. I can't call this method directly from java code as it is inherited from class that in another package. I can't find a way to specify this method to stub in in when(...)

                  package a;
                  
                  public class A() {
                      protected int m() {}
                  }
                  
                  package b;
                  
                  public class B extends a.A {
                      // this class currently does not override m method from a.A
                      public asd() {}
                  }
                  
                  // test
                  package b;
                  
                  class BTest {
                      @Test
                      public void testClass() {
                          B instance = PowerMockito.spy(new B());
                          PowerMockito.when(instance, <specify a method m>).thenReturn(123);
                          //PowerMockito.when(instance.m()).thenReturn(123); -- obviously does not work
                      }
                  }
                  

                  我查看了 PowerMockito.when 覆蓋,這似乎都只用于私有方法!

                  I looked at PowerMockito.when overrides and this seems that they are all for private methods only!

                  如何指定受保護的方法?

                  How to specify protected method?

                  推薦答案

                  簡而言之:不能總是使用 when 來存根間諜;使用 doReturn.

                  Nutshell: Can't always use when to stub spies; use doReturn.

                  假設 spydoReturn(都是 PowerMockito)的靜態導入:

                  Assuming static imports of spy and doReturn (both PowerMockito):

                  @RunWith(PowerMockRunner.class)
                  @PrepareForTest(B.class)
                  public class BTest {
                      @Test public void testClass() throws Exception {
                          B b = spy(new B());
                          doReturn(42).when(b, "m");
                          b.asd();
                      }
                  }
                  

                  您也可以@PrepareForTest(A.class) 并在when(a, "m") 上設置doReturn.哪個更有意義取決于實際測試.

                  You could also @PrepareForTest(A.class) and set up the doReturn on when(a, "m"). Which makes more sense depends on the actual test.

                  這篇關于模擬受保護的方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                  <i id='QGNWa'><tr id='QGNWa'><dt id='QGNWa'><q id='QGNWa'><span id='QGNWa'><b id='QGNWa'><form id='QGNWa'><ins id='QGNWa'></ins><ul id='QGNWa'></ul><sub id='QGNWa'></sub></form><legend id='QGNWa'></legend><bdo id='QGNWa'><pre id='QGNWa'><center id='QGNWa'></center></pre></bdo></b><th id='QGNWa'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='QGNWa'><tfoot id='QGNWa'></tfoot><dl id='QGNWa'><fieldset id='QGNWa'></fieldset></dl></div>

                      <bdo id='QGNWa'></bdo><ul id='QGNWa'></ul>

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

                        1. <legend id='QGNWa'><style id='QGNWa'><dir id='QGNWa'><q id='QGNWa'></q></dir></style></legend>
                        2. <tfoot id='QGNWa'></tfoot>
                              <tbody id='QGNWa'></tbody>

                            主站蜘蛛池模板: 国产色| av黄色免费 | 国产蜜臀97一区二区三区 | 一区二区视频在线 | 国产专区免费 | 黑人一级黄色大片 | 久久网日本 | 久久久久久久久久久福利观看 | 成人在线电影在线观看 | 国产乱码精品一区二区三区忘忧草 | 涩涩视频在线观看 | 涩涩导航 | 日日摸日日添日日躁av | 国产在线观看 | 久久r免费视频 | 国产一区三区在线 | 成人久久久久 | 欧美性视频在线播放 | 成人国产毛片 | 午夜精品久久久久久久久久久久 | 亚洲色视频 | 麻豆av网站 | 亚洲午夜精品 | 欧美日韩在线一区 | 国产精品亚洲一区 | 三区在线观看 | 欧美 日韩 在线播放 | 精品免费av | 久久久久久久亚洲精品 | 中文字幕日韩av | 99久久精品免费看国产小宝寻花 | 精品亚洲一区二区三区 | 一色桃子av一区二区 | 一级黄色录像毛片 | 国产999精品久久久影片官网 | 欧美1级 | 在线观看视频亚洲 | 日本久久一区二区三区 | 国产成人综合一区二区三区 | 91视频在线 | 色爽女|