Take the 2-minute tour ×

I have a setup like this:

class PriceAwareSpec extends Specification  {


 running(FakeApplication()) {

 val price = "CHF 50.00"
 val priceAsHtml: Html = Html(price)

 val context: Context = ContextAccessUtil.getContext
 val stateAccess = ServiceFactoryUtil.getService(context, classOf[StateAccess])

 "price aware template" should {

   "per default" in {

    stateAccess.store(StateKeys.HIDE_NETTO_KEY, java.lang.Boolean.FALSE)

     "show netto" in {
       val html = views.html.price.priceAware(priceAsHtml, true)(request)
       contentAsString(html) must contain(price)

     "show brutto" in {
       val html = views.html.price.priceAware(priceAsHtml, false)(request)
       contentAsString(html) must contain(price)

With the call to


There is an access to the play Cache with a


which does try to get the information from the current application (=FakeApplication() ?)

This results in a NullPointerException:

[error]       NullPointerException: null (Cache.scala:-1)
[error] play.api.cache.Cache$.get(Cache.scala:57)
[error] play.api.cache.Cache.get(Cache.scala)
[error] play.cache.Cache.get(Cache.java:16)

This is indicating that there is no Application present....?!

Is there something wrong with my setup?

share|improve this question
add comment

1 Answer

As mentioned on the Play 2.0 wiki the contexts have to be created for each example:

"Computer model" should {

  "be retrieved by id" in new WithApplication {
    val Some(macintosh) = Computer.findById(21)

    macintosh.name must equalTo("Macintosh")

 // or, if you want to be more specific about your configuration
 "be retrieved by id" in new 
    WithApplication(FakeApplication(additionalConfiguration = inMemoryDatabase())) {


This makes sure that each example is executed in the context of a FakeApplication. On the other hand what you have done in your code is surrounding the creation of the examples with a FakeApplication which has no impact on their execution. Note that the next version of Play 2.0 should have an even easier version for what you're trying to do:

class MySpec extends Specification with ApplicationExample {

  // only override if necessary
  implicit override val app = 
    FakeApplication(additionalConfiguration = Map("foo" -> "bar"))

  "something" should {

share|improve this answer
Sadly I cannot convince the compiler to handle the example 'in new WithApplication'. Neither did the mixing trait of ApplicationExample work. I'm working with Play Version 2.0.4 –  linuxswords Nov 27 '12 at 13:26
add comment

Your Answer


