Last active
January 23, 2016 06:01
-
-
Save rethab/01fde763d10f29273d43 to your computer and use it in GitHub Desktop.
Enhanced WithApplication class to test Play 2.4 applications with dependency injection using
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Provides Messages implicit and the default Guice-Container | |
* into the context for testing Play 2.4 applications. | |
* | |
* Sample: | |
* | |
* "use the overridden bindigs" in new WithFancyApp( | |
* lang = Lang("en", "US"), | |
* overrideModules = Seq(bind[MyInterface].to[MyImplementation]) | |
* ) { | |
* // test stuff with all regular bindings plus the ones from above | |
* } | |
* | |
*/ | |
class WithFancyApp(lang: Lang = Lang.defaultLang, | |
overrideModules: Seq[GuiceableModule] = Seq()) extends | |
WithApplication( | |
app = | |
new GuiceApplicationBuilder() | |
.in(Environment(new File("."), getClass.getClassLoader, Mode.Test)) | |
.loadConfig(env => Configuration.load(env)) | |
.overrides(overrideModules:_*) | |
.bindings() | |
.build | |
) { | |
implicit def messages: Messages = Messages(lang, app.injector.instanceOf[MessagesApi]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment