Created
July 1, 2011 17:40
-
-
Save erikvanoosten/1059045 to your computer and use it in GitHub Desktop.
Example of a specs2 unit test, with mocks and rich context
This file contains hidden or 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
import org.specs2.mutable._ | |
import org.specs2.mock._ | |
import org.specs2.specification.Scope | |
class ParentElementStrategyTest extends SpecificationWithJUnit with Mockito { | |
"The ParentElementStrategy" should { | |
"extract a user ref" in new SimpleContext { | |
val testColumn = mock[Column] | |
registry.get("urn:grons.nl:user:9475877") returns testColumn | |
userStrategy("user").getShardForEntity(ad, columns) must beTheSameAs(testColumn) | |
} | |
} | |
trait SimpleContext extends Scope { | |
val registry = mock[Registry] | |
def userStrategy(element: String) = { | |
val userStrategy = new ParentElementStrategy(element) | |
userStrategy.setRegistry(registry) | |
userStrategy | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment