How can expectedException be declared so that only Exceptions and subclasses can be passed? At present I am using expectedException: Any.
Details.
I have a test utility method that is invoked like this,
assertExceptionThrown("En-passant should be rejected when the previous move was not a double advance", classOf[UnreachablePositionException] ) {
e.rejectIllegalMove(EnPassant("e5", "d6"))
}
The second argument of the first parameter list is classOf[SomeException]. This the signature of the test method,
// TODO: Restrict expectedException to Exception or subclass
def assertExceptionThrown(assertion: String, expectedException: Any)(b: => Unit) {
My question is how can expectedException be declared so that only Exceptions and subclasses can be passed? At present I am using expectedException: Any.
The full source of the Test trait is here,
https://github.com/janekdb/stair-chess/blob/master/src/test/Test.scala
Use generics:
This says that the type
TfromexpectedExceptionmust beSomeExceptionor a subclass thereof.A demonstration: