Skip to content

Instantly share code, notes, and snippets.

@baybatu
Last active September 21, 2020 07:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/2542194cb9e5a97ba9712bcc4c1e1098 to your computer and use it in GitHub Desktop.
Save baybatu/2542194cb9e5a97ba9712bcc4c1e1098 to your computer and use it in GitHub Desktop.
Mockito deep stubs for nested objects
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private NestedObject nestedObject;

example usage in a test method:

when(nestedObject.getStatusInfo().getValue().getStatus()).thenReturn(1);
@chaoyangnz
Copy link

if the last method in the chain is void return, you need some tricks to stub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment