junit - Not able to mock constructor using PowerMock -


here in below code not able mock constructor using powermock. want mock below statement.

apspportletrequest wrappedrequest = new apspportletrequest(request); 

below mocking steps

@preparefortest({apspportletrequest.class}) @runwith(powermockrunner.class) public class reminderportletcontrollertest {     private portletrequest requestmock;    private apspportletrequest apspportletrequestmock;     public void setup() throws exception {       requestmock = easymock.createnicemock(portletrequest.class);       apspportletrequestmock = easymock.createnicemock(apspportletrequest.class);    }     @test    public void testexecutemethod() throws exception {        powermock.expectnew(apspportletrequest.class, requestmock).andreturn(apspportletrequestmock).anytimes();        easymock.replay(apspportletrequestmock, requestmock);       powermock.replayall();    } } 

please suggest me on that.

as want mock line

apspportletrequest wrappedrequest = new apspportletrequest(request); 

this object creation call takes 1 parameter,but while mocking in test method passing 2 values expectnew method.

actually should doing

powermock.expectnew(apspportletrequest.class, easymock.anyobject(requestclass.class)).andreturn(apspportletrequestmock).anytimes(); 

by doing telling compiler return mocked instance apspportletrequestmock whenever 'new' operator called on class apspportletrequest object of request class parameter.

and missing small point need replay easymock objects too.. i.e. easymock.replay(...); needs present.

hope helps!

good luck!


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -