Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
21 changes: 21 additions & 0 deletions
21
framework/src/play-test/src/test/java/play/test/WithApplicationTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (C) 2009-2016 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
package play.test; | ||
|
||
import org.junit.Test; | ||
import play.i18n.MessagesApi; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
/** | ||
* Tests WithApplication functionality. | ||
*/ | ||
public class WithApplicationTest extends WithApplication { | ||
|
||
@Test | ||
public void withInject() { | ||
MessagesApi messagesApi = inject(MessagesApi.class); | ||
assertNotNull(messagesApi); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
framework/src/play-test/src/test/scala/play/api/test/InjectingSpec.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2009-2016 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
package play.api.test | ||
|
||
import org.specs2.mock.Mockito | ||
import org.specs2.mutable._ | ||
import play.api.Application | ||
import play.api.inject.Injector | ||
|
||
import scala.language.reflectiveCalls | ||
|
||
class InjectingSpec extends Specification with Mockito { | ||
|
||
class Foo | ||
|
||
class AppContainer(val app: Application) | ||
|
||
"Injecting trait" should { | ||
|
||
"provide an instance when asked for a class" in { | ||
val injector = mock[Injector] | ||
val app = mock[Application] | ||
app.injector returns injector | ||
val expected = new Foo | ||
injector.instanceOf[Foo] returns expected | ||
|
||
val appContainer = new AppContainer(app) with Injecting | ||
val actual: Foo = appContainer.inject[Foo] | ||
actual must_== expected | ||
} | ||
} | ||
} |