我正在进行一个项目并将其升级到Play 2.5(从2.1开始)。我遇到的一个问题是这个测试:
val actualResult : Result = ...
val it = Iteratee.fold[Html, List[Html]](List.empty) {
(a, b) => {
b :: a
}
}
val bodyIt = actualResult.body.asInstanceOf[Enumerator[Html]].apply(it)
val bodyItResult = Await.result(bodyIt, 1 second)
val bodyList = Await.result(bodyItResult.run, 1 second)
val bodyText = bodyList.toString
bodyText should include(callbackUrl)
}
我收到错误
java.lang.ClassCastException: [B cannot be cast to play.twirl.api.Html
在迭代器中抛出。为什么不能投射物体呢?
答案 0 :(得分:1)
正如谢尔盖所指出的,这是一种类型不匹配,我解决了它如下:
val actualResult : Result = ...
val it = Iteratee.fold[Array[Byte], List[Array[Byte]]]](List.empty) {
(a, b) => {
b :: a
}
}
val bodyIt = actualResult.body.asInstanceOf[Enumerator[Html]].apply(it)
val bodyItResult = Await.result(bodyIt, 1 second)
val bodyList = Await.result(bodyItResult.run, 1 second)
val bodyBytes = bodyList.head
val bodyText = new String(bodyBytes)
bodyText should include(callbackUrl)
}