mercredi 19 août 2015

Not able to mock the protected variable of object using mockito?

I am trying to Mock the object but failing.

Class A {
protected SomeResponse someRespsoonse;


public SomeResponse mapping(){

someResponse = new SomeResponse();

return someResponse ;
} 
}

Then i need to test it with following class:

@RunWith(MockitoJUnitRunner.class)
@PrepareForTest(A.class)
class ATest{
@Mock
A a = Mocktio.mock(A.class);
@Mock               
SomeResponse someResponse = Mockito.mock(SomeResponse.class);                              

@Test
testMyResponse{                
someResponse.setErrorInfo("500");                

PowerMockito.whenNew(SomeResponse.class).withNoArguments().thenReturn(someResponse);                
a.mapping();                

// some blah blah              

}}                          

Issue is am not able to populate the SomeResponse object from the test class. I went through the Stackoverflow and google. but couldn't get thing which am looking for.

Aucun commentaire:

Enregistrer un commentaire