Skip to content

Instantly share code, notes, and snippets.

@rowanl
Created January 17, 2018 19:59
Show Gist options
  • Save rowanl/d41af0efc42601d943cbcdd2b88abe00 to your computer and use it in GitHub Desktop.
Save rowanl/d41af0efc42601d943cbcdd2b88abe00 to your computer and use it in GitHub Desktop.
playframework-kubernetes - Mocking time dependency in tests using Guice
public class CharityControllerTest extends WithServer {
private Clock clock;
@Override
protected Application provideApplication() {
return new GuiceApplicationBuilder()
.overrides(bindClockToMockInstance())
.build();
}
private AbstractModule bindClockToMockInstance() {
return new AbstractModule() {
@Override
protected void configure() {
bind(Clock.class).toInstance(clock = mock(Clock.class));
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment