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

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

    1. <legend id='59fqG'><style id='59fqG'><dir id='59fqG'><q id='59fqG'></q></dir></style></legend>
    2. <small id='59fqG'></small><noframes id='59fqG'>

        <bdo id='59fqG'></bdo><ul id='59fqG'></ul>

    3. <tfoot id='59fqG'></tfoot>

      使用 Mockito 在其中調用 new() 測試類

      Test class with a new() call in it with Mockito(使用 Mockito 在其中調用 new() 測試類)

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

      • <bdo id='pj9b0'></bdo><ul id='pj9b0'></ul>

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

                  <tbody id='pj9b0'></tbody>
                本文介紹了使用 Mockito 在其中調用 new() 測試類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有一個包含 new() 調用以實例化 LoginContext 對象的舊類:

                I have a legacy class that contains a new() call to instantiate a LoginContext object:

                public class TestedClass {
                  public LoginContext login(String user, String password) {
                    LoginContext lc = new LoginContext("login", callbackHandler);
                  }
                }
                

                我想使用 Mockito 來模擬 LoginContext 來測試這個類,因為它要求在實例化之前設置 JAAS 安全性內容,但我不確定如何在不更改 code>login() 方法來外部化 LoginContext.

                I want to test this class using Mockito to mock the LoginContext as it requires that the JAAS security stuff be set up before instantiating, but I'm not sure how to do that without changing the login() method to externalize the LoginContext.

                是否可以使用 Mockito 來模擬 LoginContext 類?

                Is it possible using Mockito to mock the LoginContext class?

                推薦答案

                對于未來我會推薦 Eran Harel 的回答(重構將 new 移動到可以模擬的工廠).但是,如果您不想更改原始源代碼,請使用非常方便且獨特的功能:sies.來自文檔:

                For the future I would recommend Eran Harel's answer (refactoring moving new to factory that can be mocked). But if you don't want to change the original source code, use very handy and unique feature: spies. From the documentation:

                您可以創建真實對象的間諜.當您使用 spy 時,會調用 real 方法(除非方法被存根).

                You can create spies of real objects. When you use the spy then the real methods are called (unless a method was stubbed).

                應該小心偶爾使用真正的間諜,例如在處理遺留代碼時.

                Real spies should be used carefully and occasionally, for example when dealing with legacy code.

                在你的情況下,你應該寫:

                In your case you should write:

                TestedClass tc = spy(new TestedClass());
                LoginContext lcMock = mock(LoginContext.class);
                when(tc.login(anyString(), anyString())).thenReturn(lcMock);
                

                這篇關于使用 Mockito 在其中調用 new() 測試類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                <tfoot id='OQVUS'></tfoot>
                <legend id='OQVUS'><style id='OQVUS'><dir id='OQVUS'><q id='OQVUS'></q></dir></style></legend>

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

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

                  <tbody id='OQVUS'></tbody>
                • <bdo id='OQVUS'></bdo><ul id='OQVUS'></ul>
                        • 主站蜘蛛池模板: 亚洲第一av | 精品成人一区 | 亚洲一区二区在线播放 | 亚洲在线一区二区三区 | 波多野结衣一区二区三区在线观看 | 毛片免费视频 | av中文字幕在线观看 | 国产精品一区二区三区久久久 | 人人射人人 | 国产视频中文字幕在线观看 | 久久久女女女女999久久 | 久久四虎 | 日本在线视频一区二区 | 日日干夜夜干 | 亚洲精品国产电影 | 一区二区三区网站 | 九九精品影院 | 国产精品久久网 | 国产精品久久久乱弄 | 国产精品视频久久 | 91视频在线观看 | 亚洲激情在线视频 | 久久国产精品无码网站 | 日韩欧美一区二区三区 | 欧美视频区 | 夜夜草导航 | 一区二区三区电影网 | 狠狠综合久久av一区二区老牛 | 91精品国产综合久久久久久 | 午夜影晥 | 中文字幕一区二区三区在线观看 | 毛片韩国 | 成人高清在线 | 国产成人网| 国产精品美女久久久久久免费 | 蜜桃毛片| 国产传媒视频在线观看 | 日本午夜在线视频 | 中文字幕在线免费观看 | 久久久久久久久国产成人免费 | 国产精品欧美一区二区 |