My code is of the form:
public String getDeliveryDestinations(final RequestContext requestContext {
final Accessor accessor = requestContext.getAccessor().get();
final GroupAccessor groupAccessor = accessor.getGroupAccessor();
final String groupId = groupAccessor.getGroupId();
if(groupId.equals("s1") return "Type1";
else return "type 2";
}
For testing this, i wrote the following:
@Test
public void getDestinationsDestinations_empty() throws Exception {
Accessor accessor = mock(Accessor.class);
GroupAccessor groupAccessor = mock(GroupAccessor.class);
//*mockRequestContent is Mocked*
when(mockRequestContext.getAccessor().get()).thenReturn(accessor);
when(accessor.getGroupAccessor()).thenReturn(groupAccessor);
when(groupAccessor.getGroupId()).thenReturn("s1");
String destinationResult = provider.getDeliveryDestinations(mockRequestContext);
assertEquals(destinationResult,"Type1");
}
I get a NPE at, when(mockRequestContext.getAccessor().get()).thenReturn(accessor); I don't know why!
Any leads would be very helpful :)
Aucun commentaire:
Enregistrer un commentaire