Skip to content

Commit

Permalink
Added basic functional specification
Browse files Browse the repository at this point in the history
  • Loading branch information
aloiscochard committed Aug 13, 2011
1 parent 6ac0bea commit 3fefe56
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 36 deletions.
75 changes: 75 additions & 0 deletions src/test/scala/sindi/FunctionalSpec.scala
@@ -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
}
}
46 changes: 10 additions & 36 deletions src/test/scala/sindi/Sindi.scala
@@ -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
}
}
*/
} }

0 comments on commit 3fefe56

Please sign in to comment.