Skip to content

Instantly share code, notes, and snippets.

@xCASx
Created November 24, 2014 15:37
Show Gist options
  • Save xCASx/2ee243ec4c4c59e215e7 to your computer and use it in GitHub Desktop.
Save xCASx/2ee243ec4c4c59e215e7 to your computer and use it in GitHub Desktop.
Mockito fixture template
/**
* Fixture for test.
*/
private static final class Fixture {
@Mock
CustomManager customManager;
@Mock
CustomRepository repository;
@Mock
CustomSorter sorter;
@Spy
@InjectMocks
CustomController controller = new CustomController();
Fixture() {
MockitoAnnotations.initMocks(this);
// do some general inits
}
void givenCustomManager(CustomDTO customDTO) {
doReturn(customDTO).when(customManager).manage(anyLong(), any(Date.class));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment