Reputation: 505
I am working on a Junit Test where I need to work on Easymock and Class objects together to rub the test.
Following is my code snippet
@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
}
I tried to see an example where I can use Easy mock and Class object together , I could not find that is suitable for my case. Can anybody point me to an example ?
Upvotes: 0
Views: 835
Reputation: 3448
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.
}
Upvotes: 5
Reputation: 3657
You can't mock a static method invocation using EasyMock. 2 solutions:
Upvotes: 1