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

      1. Mockito:如何存根 getter setter

        时间:2023-10-01

        • <i id='pwD3p'><tr id='pwD3p'><dt id='pwD3p'><q id='pwD3p'><span id='pwD3p'><b id='pwD3p'><form id='pwD3p'><ins id='pwD3p'></ins><ul id='pwD3p'></ul><sub id='pwD3p'></sub></form><legend id='pwD3p'></legend><bdo id='pwD3p'><pre id='pwD3p'><center id='pwD3p'></center></pre></bdo></b><th id='pwD3p'></th></span></q></dt></tr></i><div id='pwD3p'><tfoot id='pwD3p'></tfoot><dl id='pwD3p'><fieldset id='pwD3p'></fieldset></dl></div>
        • <legend id='pwD3p'><style id='pwD3p'><dir id='pwD3p'><q id='pwD3p'></q></dir></style></legend>
          • <small id='pwD3p'></small><noframes id='pwD3p'>

              <tbody id='pwD3p'></tbody>

                <tfoot id='pwD3p'></tfoot>
                • <bdo id='pwD3p'></bdo><ul id='pwD3p'></ul>
                  本文介绍了Mockito:如何存根 getter setter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我是 Mockito 的新手,我想知道如何存根获取/设置对.

                  I am kind of new to Mockito and I was wondering how I could stub a get/set pair.

                  例如

                  public interface Dummy {
                       public String getString();
                       public void setString(String string);
                  }
                  

                  如何使它们正常运行:如果在测试的某个地方调用 setString("something"); 我希望 getString() 返回something".这是可行的还是有更好的方法来处理这种情况?

                  How can I make them behave properly: if somewhere in a test I invoke setString("something"); I would like getString() to return "something". Is that feasable or is there a better way to handle such cases?

                  推荐答案

                  我还希望 getter 返回最近 setter 调用的结果.

                  I also wanted the getter to return the result of the recent setter-call.

                  拥有

                  class Dog
                  {
                      private Sound sound;
                  
                      public Sound getSound() {
                          return sound;
                      }
                      public void setSound(Sound sound)   {
                          this.sound = sound;
                      }
                  }
                  
                  class Sound
                  {
                      private String syllable;
                  
                      Sound(String syllable)  {
                          this.syllable = syllable;
                      }
                  }
                  

                  我使用以下方法将 setter 连接到 getter:

                  I used the following to connect the setter to the getter:

                  final Dog mockedDog = Mockito.mock(Dog.class, Mockito.RETURNS_DEEP_STUBS);
                  // connect getter and setter
                  Mockito.when(mockedDog.getSound()).thenCallRealMethod();
                  Mockito.doCallRealMethod().when(mockedDog).setSound(Mockito.any(Sound.class));
                  

                  这篇关于Mockito:如何存根 getter setter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:mockito ArrayList&lt;String&gt;问题 下一篇:java.util.MissingResourceException:找不到基本名称 java

                  相关文章

                  最新文章

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

                      <small id='2yLsO'></small><noframes id='2yLsO'>