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

  1. <tfoot id='bCDpW'></tfoot>

  2. <legend id='bCDpW'><style id='bCDpW'><dir id='bCDpW'><q id='bCDpW'></q></dir></style></legend>

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

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

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

      修改 void 函數的輸入參數,然后讀取

      Modify input parameter of a void function and read it afterwards(修改 void 函數的輸入參數,然后讀取)

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

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

                  <tbody id='iX34S'></tbody>
              1. <small id='iX34S'></small><noframes id='iX34S'>

              2. <legend id='iX34S'><style id='iX34S'><dir id='iX34S'><q id='iX34S'></q></dir></style></legend>

                本文介紹了修改 void 函數的輸入參數,然后讀取的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有一個相當復雜的 java 函數,我想使用 jUnit 進行測試,為此我正在使用 Mockito.這個函數看起來像這樣:

                I have a rather complex java function that I want to test using jUnit and I am using Mockito for this purpose. This function looks something like this:

                public void myFunction (Object parameter){
                   ...
                   doStuff();
                   ...
                   convert(input,output);
                   ...
                   parameter.setInformationFrom(output);
                }
                

                convert 函數根據輸入設置輸出的屬性,它是一個 void 類型的函數,盡管輸出"是參數是正在使用的,就好像它是由函數返回的一樣.這個轉換函數是我想要模擬的,因為我不需要依賴于測試的輸入,但我不知道該怎么做,因為我對 Mockito 不是很熟悉.

                The function convert sets the attributes of output depending on input and it's a void type function, although the "output" parameter is what is being used as if it were returned by the function. This convert function is what I want to mock up as I don't need to depend on the input for the test, but I don't know how to do this, as I am not very familiar with Mockito.

                我見過的基本情況是 when(something).thenReturn(somethingElse)或我理解的 doAnswer 方法與前一個方法類似,但可以添加更多邏輯,但我認為這些情況不適合我的情況,因為我的函數沒有返回語句.

                I have seen basic cases as when(something).thenReturn(somethingElse) or the doAnswer method which I understand is similar to the previous one but more logic can be added to it, but I don't think these cases are appropriate for my case, as my function does not have a return statement.

                推薦答案

                如果您希望模擬方法在(或以其他方式更改)參數上調用方法,您需要像這個問題一樣寫一個答案(如何模擬影響對象的 void 返回方法").

                If you want the mocked method to call a method on (or otherwise alter) a parameter, you'll need to write an Answer as in this question ("How to mock a void return method affecting an object").

                來自 Kevin Welker 的 回答那里:

                doAnswer(new Answer() {
                    Object answer(InvocationOnMock invocation) {
                        Object[] args = invocation.getArguments();
                        ((MyClass)args[0]).myClassSetMyField(NEW_VALUE);
                        return null; // void method, so return null
                    }
                }).when(mock).someMethod();
                

                請注意,較新的最佳實踐將具有 Answer 的類型參數,如 Answer,并且 Java 8 的 lambda 可以進一步壓縮語法.例如:

                Note that newer best-practices would have a type parameter for Answer, as in Answer<Void>, and that Java 8's lambdas can compress the syntax further. For example:

                doAnswer(invocation -> {
                  Object[] args = invocation.getArguments();
                  ((MyClass)args[0]).myClassSetMyField(NEW_VALUE);
                  return null; // void method in a block-style lambda, so return null
                }).when(mock).someMethod();
                

                這篇關于修改 void 函數的輸入參數,然后讀取的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                    • <bdo id='06iGZ'></bdo><ul id='06iGZ'></ul>
                    • <i id='06iGZ'><tr id='06iGZ'><dt id='06iGZ'><q id='06iGZ'><span id='06iGZ'><b id='06iGZ'><form id='06iGZ'><ins id='06iGZ'></ins><ul id='06iGZ'></ul><sub id='06iGZ'></sub></form><legend id='06iGZ'></legend><bdo id='06iGZ'><pre id='06iGZ'><center id='06iGZ'></center></pre></bdo></b><th id='06iGZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='06iGZ'><tfoot id='06iGZ'></tfoot><dl id='06iGZ'><fieldset id='06iGZ'></fieldset></dl></div>

                      1. <legend id='06iGZ'><style id='06iGZ'><dir id='06iGZ'><q id='06iGZ'></q></dir></style></legend>

                          <small id='06iGZ'></small><noframes id='06iGZ'>

                            <tbody id='06iGZ'></tbody>
                        • <tfoot id='06iGZ'></tfoot>
                        • 主站蜘蛛池模板: 国产在线精品一区二区 | 日本三级视频 | 国产一区二区三区四区在线观看 | 国产精品18久久久久久白浆动漫 | 国产一区二区免费电影 | 美国av片在线观看 | 久久精品亚洲国产奇米99 | 亚洲一区二区三区在线视频 | 欧美极品在线播放 | 91在线网站 | xnxx 日本免费| 成人在线视频网 | 女女百合av大片一区二区三区九县 | 午夜精品一区二区三区在线视频 | 亚洲欧美一区二区三区在线 | 欧美在线一区二区三区 | 91在线看 | 日韩av免费看 | 国产在线中文字幕 | 日韩一区二区三区av | 国产精品欧美一区喷水 | 免费观看一级特黄欧美大片 | 91一区二区 | 中文字幕第十五页 | 亚洲国产精品99久久久久久久久 | 狠狠天天 | 九九免费视频 | 国产在线视频99 | 欧美性tv | 日韩精品免费在线观看 | 精品一区免费 | 国产成人精品一区二区三区四区 | 五十女人一级毛片 | 岛国精品 | 久久久久国产精品一区二区 | www.狠狠操| 国产福利在线 | 久久久久久久电影 | 天天曰夜夜 | 一区二区精品电影 | 在线成人 |