title: How to test controllers using deadbolt2 DeadboltActions or is there another framework which allows this easily?
body: <p>I'm using Play! 2.4 with Deadbolt2 for authorization. However, since I introduced the authorization rules, I'm unable to write successful tests for my controllers. As an example:</p>
  
  <pre><code>class VisitController @Inject() (authorization: DeadboltActions) extends Controller {
    def fetchDailyVisits(date: Date) = authorization.Restrict(List(Array(ADMIN_ROLE), Array(MANAGER_ROLE))) {
      Action.async {
        visitService.findDailyVisits(date).map(result =&gt;
          Ok(Json.toJson(result))
        )
      }
    }
  }
  </code></pre>
  
  <p>I'm using specs2 in the tests. My test looks like this atm:</p>
  
  <pre><code>class VisitControllerSpec extends PlaySpecification with Mockito with ScalaFutures {
    val deadboltActions = mock[DeadboltActions]
  "VisitControllerSpec#fetchDailyVisits" should {
  
      val testDate = Date.from(LocalDate.of(2016, 2, 25)
        .atStartOfDay(ZoneId.systemDefault()).toInstant)
  
      "Return Status Ok with returned list" in {
  
        val expected = List(completeVisitWithId, anotherCompleteVisitWithId)
        visitService.findDailyVisits(testDate) returns Future { expected }
  
        val request = FakeRequest(GET, "/visits?date=2016-02-25")
  
        val result = new VisitController(deadboltActions)
          .fetchDailyVisits(testDate)(request)
  
        result.futureValue.header.status must beEqualTo(OK)
        contentAsJson(result) must_== Json.toJson(expected)
      }
    }
  }
  </code></pre>
  
  <p>How do I mock deadboltActions in a way I can specify the user will be allowed access?</p>
  
  <p>Is there another way? Maybe by providing a different DeadboltHandler? It seems kind of obvious this would be the way to go, I just don't seem to be able to figure it out and there aren't a lot of Deadbolt2 examples out there (at least for scala).</p>
  
  <p>Or, being more extreme, any other  authorization framework out there that works well with scala play and allows to handle security as a cross-cutting concern without poluting the controllers? Deadbolt2 is too limited for this reason, but I honestly can't find a better authorization framework (unless I write my own).</p>