Skip to content

Instantly share code, notes, and snippets.

@sebhoss
Last active April 19, 2021 02:31
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebhoss/fb41b560672ce3cdd341 to your computer and use it in GitHub Desktop.
Save sebhoss/fb41b560672ce3cdd341 to your computer and use it in GitHub Desktop.
DSLContext database = Mockito.mock(DSLContext.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(database.select(ACTIVITY_TYPE.ID)
.from(ACTIVITY_TYPE)
.where(ACTIVITY_TYPE.SINGLE_PERSON_USABLE.isTrue())
.fetch(ACTIVITY_TYPE.ID))
.thenReturn(ImmutableList.of(singleActivityTypeId));
Mockito.when(database.select(ACTIVITY_TYPE.ID)
.from(ACTIVITY_TYPE)
.where(ACTIVITY_TYPE.MULTI_PERSON_USABLE.isTrue())
.fetch(ACTIVITY_TYPE.ID))
.thenReturn(ImmutableList.of(multiActivityTypeId));
@sarnobat
Copy link

sarnobat commented Sep 6, 2018

I like the programmatic deep stubbing:

DSLContext database = Mockito.mock(DSLContext.class, Mockito.RETURNS_DEEP_STUBS);

I like to keep annotations to a minimum. Otherwise you have no idea what your annotation-heavy code does (which is the same reason I hate Spring).

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