I am trying to mock one of my private method , it is a must for me to mock it . Can any one help me on this . Because my code tries to traverses through the code .I dont need to traverse through the method . I just need to mock my private method and returns a String . Below is my method
Please note : I have referred all the duplicate marked questions, I tried all those and I am unable to find a solution. Please help. Also one of my parameter is a byte array .
private String decodeResponse(byte bresp[])
{
String spresp = null;
byte bcontent[] = new byte[bresp.length - 2];
for(int i = 0; i < bcontent.length; i++)
bcontent[i] = bresp[i + 1];
try
{
spresp = new String(bcontent, "US-ASCII");
}
catch(UnsupportedEncodingException ex)
{
return null;
}
return spresp;
}
Below is my test class
@PrepareForTest(SPSocketCommunicator.class)
@RunWith(PowerMockRunner.class)
public class SPSocketCommunicatorTest{
@test
public void test() throws Exception {
byte[] temp = null;
SPSocketCommunicator socketCommunicator=new SPSocketCommunicator(request, Map);
SPSocketCommunicator spy = PowerMockito.spy(socketCommunicator);
PowerMockito.spy(SPSocketCommunicator.class);
PowerMockito.doReturn("a string").when(spy,"decodeResponse",Matchers.<byte[]>any());
socketCommunicator.decodeResponse(temp);
}
}