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 閱讀(547) 評論(0)  編輯  收藏 所屬分類: Unit Test


          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 旬阳县| 眉山市| 尉犁县| 仁怀市| 滨州市| 新营市| 贵港市| 神农架林区| 海南省| 巴塘县| 田阳县| 乐清市| 基隆市| 洛浦县| 常宁市| 平山县| 竹溪县| 九江县| 边坝县| 徐州市| 宜宾县| 阿拉尔市| 临泉县| 仁寿县| 札达县| 盘山县| 绥滨县| 桐柏县| 江北区| 宁明县| 昭觉县| 贵定县| 遵义县| 昌都县| 遂宁市| 铜鼓县| 屯门区| 上林县| 讷河市| 大理市| 兴安盟|