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


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


          網(wǎng)站導(dǎo)航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 康定县| 吴桥县| 芒康县| 蛟河市| 霍州市| 江华| 申扎县| 会昌县| 凉山| 鹤壁市| 宝鸡市| 瑞昌市| 天台县| 普安县| 广河县| 晋宁县| 关岭| 扎囊县| 商都县| 普兰县| 板桥市| 丰原市| 麻城市| 龙游县| 宁晋县| 万源市| 利津县| 阿拉尔市| 中江县| 高唐县| 专栏| 电白县| 黄大仙区| 红原县| 元氏县| 哈尔滨市| 云阳县| 健康| 容城县| 博客| 遂川县|