java - Mocking static fields with Mockito -
i have (it 3rd party library have work design):
classa.conn1.getobjecta().getintvalue()
classa normal class, , within there public static field (conn1). conn1 class have connection , other values used in application (in case objecta).
this value passed parameter in dao mocking. value mocked matchers.anyint() nullpointerexception because conn1 null (not expected int)
i tried things powermockito, whitebox, without success. have done this, same nullpointerexception
mockito.when(classa.conn1.getobjecta()).thenreturn(new objecta(2));
the question is, how can mock objecta or int value of objecta
import static x.y.z.mockito.*; objecta objecta = mock(objecta.class); when(objecta.getintvalue()).thenreturn(1)); conn conn1 = mock(conn.class); when(conn1.getobjecta()).thenreturn(objecta); classa.conn1 = conn1;
java unit-testing mocking mockito
No comments:
Post a Comment