使用Easy Mock对象

KAP*_*ILP 0 java junit unit-testing easymock

我正在进行Junit测试,我需要将Easymock和Class对象一起工作来测试.

以下是我的代码段

@Before
public void setUp() {
    request=EasyMock.createMock(SlingHttpServletRequest.class);
    response=EasyMock.createMock(SlingHttpServletResponse.class);

}

@Test
public void testImage() {

RequestContext ctx = new RequestContext();  

// RequestContext and RequestContext Util are both classes defined in Project

    expect(RequestContextUtil.setupContext(request,response)).andReturn(ctx);

    // This line is throwing an error , so I am not able to add replay or verify method

}
Run Code Online (Sandbox Code Playgroud)

我试着看一个例子,我可以一起使用Easy mock和Class对象,我找不到适合我的情况.任何人都能指出我的一个例子吗?

Par*_*nki 5

private MockHttpServletRequest request;
private MockHttpServletResponse response;

 @Before
 public void setup() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
}

    @Test
    public void testImage() {
      //here you don't need to `expect` or `reply` 

     // `request` and `response` is mock now. 
   }
Run Code Online (Sandbox Code Playgroud)