Last active
August 29, 2015 13:56
-
-
Save johnlcox/9176734 to your computer and use it in GitHub Desktop.
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
class MyInjectable() { | |
val myString = "my String" | |
} | |
trait MyTrait { | |
@Inject | |
val myInjectable: MyInjectable = null // Initialize to null so that it isn't abstract and will be injected by guice. Is there a better way to do this though? | |
} | |
class MyObject extends Controller with MyTrait {} | |
@RunWith(classOf[JUnitRunner]) | |
class MixinInjectionSpec extends Specification { | |
"Guice" should { | |
"inject the mixin trait" in { | |
val injector = Guice.createInjector() | |
val myObject = injector.getInstance(classOf[MyObject]) | |
myObject.myInjectable.myString must equalTo("my String") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment