dimanche 26 juillet 2020

Mockito on continuous Optional classes

This is the code block I'm working with:

Optional<Response> response = something.get();
Optional<String> content = response.map(Response::getContent);
ObjectNode head = objectMapper.readValue(content.get(), ObjectNode.class);

// then I'm going to work with this "head"

I got Cannot mock/spy class java.util.Optional before, so I know I cannot mock Optional. Since I don't have "something", I'm doing:

@Mock private Something something;
@Mock Response res;

when(something.get()).thenReturn(Optional.of(res));

But I don't know how to mock the next two lines.

I have constructed a "head" and I want to test with this one I created.

Hope I make myself clear. Thanks!

Aucun commentaire:

Enregistrer un commentaire