thinking

          one platform thousands thinking

          Mock void method

          I have a method that returns void in a class that is a dependency of the class I want to test.

          This class is huge and I'm only using this single method from it. I need to replace the implementation of this method for the test as I want it to do something different and I need to be able to access the parameters this method receives.

          I cannot find a way of doing this in EasyMock. I think I know how to do it with Mockito by using doAnswer but I don't want to add another library unless absolutely necessary.


          If I understand what you want to do correctly, you should be able to use andAnswer():

          mockObject.someMethod(eq(param1), eq(param2);

          expectLastCall().andAnswer(newIAnswer(){
              publicObject answer(){
                  
          //supply your mock implementation here

                  SomeClass arg1 
          =(SomeClass) getCurrentArguments()[0];

                  AnotherClass arg2 
          =(AnotherClass) getCurrentArguments()[1];

                  arg1.doSomething(blah);

                  
          //return the value to be returned by the method (null for void)

                  returnnull;

              }

          });

          posted on 2010-04-21 18:23 lau 閱讀(551) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Unit Test


          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 旬阳县| 嘉荫县| 台湾省| 甘孜县| 安泽县| 马关县| 四会市| 涡阳县| 区。| 镇江市| 永仁县| 大港区| 恩施市| 巴南区| 平武县| 卫辉市| 霞浦县| 霍州市| 崇礼县| 灵武市| 合川市| 孙吴县| 英超| 长沙市| 仙游县| 体育| 枣阳市| 武清区| 遂川县| 古浪县| 鸡西市| 宾阳县| 乌鲁木齐县| 宜兰县| 永泰县| 广昌县| 罗定市| 潼南县| 册亨县| 那曲县| 城口县|