Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic functional specification
- Loading branch information
1 parent
6ac0bea
commit 3fefe56
Showing
2 changed files
with
85 additions
and
36 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,75 @@ | |||
// _____ ___ | |||
// / __(_)__ ___/ (_) | |||
// _\ \/ / _ \/ _ / / | |||
// /___/_/_//_/\_,_/_/ | |||
// | |||
// (c) 2011, Alois Cochard | |||
// | |||
// http://aloiscochard.github.com/sindi | |||
// | |||
|
|||
package sindi | |||
|
|||
import org.specs2.mutable._ | |||
|
|||
class FunctionalSpec extends Specification { | |||
|
|||
"Sindi" should { | |||
"throw an exception when type is not bound" in { | |||
class Foo extends Context | |||
new Foo().inject[String] must throwAn[RuntimeException] | |||
} | |||
|
|||
"bind concrete type" in { | |||
class Foo extends Context { override val bindings: Bindings = bind[String] to "sindi" } | |||
new Foo().inject[String] mustEqual "sindi" | |||
} | |||
|
|||
"bind concrete type with qualifier" in { | |||
class Foo extends Context { override val bindings: Bindings = bind[String] to "sindi" as "sindi"} | |||
val foo = new Foo | |||
foo.inject[String] must throwAn[RuntimeException] | |||
foo.injectAs[String]("sindi") mustEqual "sindi" | |||
} | |||
|
|||
"bind concrete type with scope" in { | |||
class Bar | |||
var state = 1 | |||
class Foo extends Context { override val bindings: Bindings = bind[Bar] to new Bar scope { state } } | |||
val foo = new Foo | |||
val bar1 = foo.inject[Bar].hashCode | |||
bar1 mustEqual foo.inject[Bar].hashCode | |||
state = 2 | |||
bar1 mustNotEqual foo.inject[Bar].hashCode | |||
} | |||
|
|||
"bind abstract type" in { | |||
class Foo extends Context { override val bindings: Bindings = bind[String] to "sindi" } | |||
new Foo().inject[AnyRef] mustEqual "sindi" | |||
} | |||
|
|||
"bind abstract type with FIFO priority" in { | |||
class FooA extends Context { override val bindings = Bindings(bind[AnyRef] to "scala", | |||
bind[String] to "sindi") } | |||
val fooA = new FooA | |||
fooA.inject[AnyRef] mustEqual "scala" | |||
fooA.inject[String] mustEqual "sindi" | |||
|
|||
class FooB extends Context { override val bindings = Bindings(bind[String] to "sindi", | |||
bind[AnyRef] to "scala") } | |||
val fooB = new FooB | |||
fooB.inject[String] mustEqual "sindi" | |||
fooB.inject[AnyRef] mustEqual "sindi" | |||
} | |||
|
|||
"bind parameterized type" in { | |||
val list = List("sindi") | |||
class Foo extends Context { override val bindings: Bindings = bind[List[String]] to list } | |||
new Foo().inject[List[String]] mustEqual list | |||
new Foo().inject[List[AnyRef]] mustEqual list | |||
|
|||
} | |||
|
|||
// TODO [aloiscochard] Test scope, qualifier, factory, Option | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,42 +1,16 @@ | |||
// _____ ___ | |||
// / __(_)__ ___/ (_) | |||
// _\ \/ / _ \/ _ / / | |||
// /___/_/_//_/\_,_/_/ | |||
// | |||
// (c) 2011, Alois Cochard | |||
// | |||
// http://aloiscochard.github.com/sindi | |||
// | |||
|
|||
package sindi | package sindi | ||
|
|
||
import org.specs2.mutable._ | import org.specs2.mutable._ | ||
|
|
||
class Foo | |||
|
|||
class SindiSpec extends Specification { | class SindiSpec extends Specification { | ||
|
|||
/* | |||
"Injector Companion" should { | |||
"create binding from instance" in { | |||
val foo = new Foo | |||
val binding = Injector.bind[Foo](foo) | |||
(binding._1 eq foo.getClass) must beTrue | |||
(binding._2() eq foo) must beTrue | |||
} | |||
"create binding from class" in { | |||
val binding = Injector.bind[Foo](classOf[Foo]) | |||
val fooA = binding._2() | |||
val fooB = binding._2() | |||
(binding._1 eq new Foo().getClass) must beTrue | |||
(fooA ne fooB) must beTrue | |||
} | |||
"create binding from function" in { | |||
val foo = new Foo | |||
val function = () => foo | |||
val binding = Injector.bind[Foo](foo) | |||
(binding._1 eq foo.getClass) must beTrue | |||
(binding._2() eq foo) must beTrue | |||
} | |||
} | |||
"Injector" should { | |||
"accept an input size of 16 bytes only" in { | |||
new UID((0 to 14).map(_.toByte).toList) must throwAn[IllegalArgumentException] | |||
new UID((0 to 16).map(_.toByte).toList) must throwAn[IllegalArgumentException] | |||
new UID((0 to 15).map(_.toByte).toList) must not be null | |||
} | |||
} | |||
*/ | |||
} | } |