用easymock 处理mock的对象的set/get方法

private void expectSomeClassGetSetProperty(SomeClass p) {
    final Capture<Integer> captureInt = new Capture<Integer>();
    p.setProperty( capture(captureInt) );
    expectLastCall().once();
    IAnswer<Integer> answer = new IAnswer<Integer>() {
      private Capture<Integer> capture = captureInt;
      public Integer answer()
        throws Throwable
      {
        return capture.getValue();
      }
    };
    expect(p.getProperty()).andAnswer( answer ).anyTimes();
  }

 

用easymock的capture和answer配对 实现set/get操作的mock

你可能感兴趣的:(easymock)