Skip to content

Instantly share code, notes, and snippets.

@Dalamar42
Last active July 27, 2016 13:17
Show Gist options
  • Save Dalamar42/25797642b9c0d1dc4684708138915d7b to your computer and use it in GitHub Desktop.
Save Dalamar42/25797642b9c0d1dc4684708138915d7b to your computer and use it in GitHub Desktop.
// This is the stub generated by our fictional framework
Database mockDatabase = mock(Database.class);
// Class that we want to test and that uses mockDatabase
ApplicationService service = new ApplicationService(stubDatabase);
// Here we are telling the stub what to return
when(mockDatabase.getApplicationKey(APP_ID))
.thenReturn(new ApplicationKey(APP_ID, Status.REVOKED));
// Test ApplicationService behaviour
assertThat(service.isRevoked(APP_ID), is(true));
// Verify the the expected method with the expected parameters
// was called on the mock
verify(mockDatabase).getApplicationKey(APP_ID);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment