org.scalatest

trait Assertions

[source: org/scalatest/Assertions.scala]

trait Assertions
extends AnyRef
Trait that contains ScalaTest's basic assertion methods.
Author
Bill Venners
Direct Known Subclasses:
Assertions, Suite, Matchers

Method Summary
def assert (condition : Boolean, message : Any) : Unit
Assert that a boolean condition, described in String message, is true. If the condition is true, this method returns normally. Else, it throws TestFailedException with the String obtained by invoking toString on the specified message as the exception's detail message.
def assert (condition : Boolean) : Unit
Assert that a boolean condition is true. If the condition is true, this method returns normally. Else, it throws TestFailedException.
def assert (o : scala.Option[java.lang.String], message : Any) : Unit
Assert that an Option[String] is None. If the condition is None, this method returns normally. Else, it throws TestFailedException with the String value of the Some, as well as the String obtained by invoking toString on the specified message, included in the TestFailedException's detail message.
def assert (o : scala.Option[java.lang.String]) : Unit
Assert that an Option[String] is None. If the condition is None, this method returns normally. Else, it throws TestFailedException with the String value of the Some included in the TestFailedException's detail message.
implicit def convertToEqualizer (left : Any) : Equalizer
Implicit conversion from Any to Equalizer, used to enable assertions with === comparisons. For more information on this mechanism, see the documentation for Equalizer.
def expect (expected : Any)(actual : Any) : Unit
Expect that the value passed as expected equals the value passed as actual. If the actual value equals the expected value (as determined by ==), expect returns normally. Else, expect throws an TestFailedException whose detail message includes the expected and actual values.
def expect (expected : Any, message : Any)(actual : Any) : Unit
Expect that the value passed as expected equals the value passed as actual. If the actual equals the expected (as determined by ==), expect returns normally. Else, if actual is not equal to expected, expect throws an TestFailedException whose detail message includes the expected and actual values, as well as the String obtained by invoking toString on the passed message.
def fail (message : java.lang.String, cause : java.lang.Throwable) : Nothing
Throws TestFailedException, with the passed String message as the exception's detail message and Throwable cause, to indicate a test failed.
def fail (message : java.lang.String) : Nothing
Throws TestFailedException, with the passed String message as the exception's detail message, to indicate a test failed.
def fail (cause : java.lang.Throwable) : Nothing
Throws TestFailedException, with the passed Throwable cause, to indicate a test failed. The getMessage method of the thrown TestFailedException will return cause.toString().
def fail : Nothing
Throws TestFailedException to indicate a test failed.
def intercept [T <: AnyRef](clazz : java.lang.Class[T], message : Any)(f : => Any) : T
Deprecated: use the more concise version of intercept, which uses an implicit manifest. Note: there is currently no version of the "implicit manifest" form of intercept that takes a string message. The reason is it won't overload while these older forms are still in the API. Once these deprecated forms are removed, an overloaded version of intercept that takes a string message and implicit manifest will be added. Intercept and return an instance of the passed exception class (or an instance of a subclass of the passed class), which is expected to be thrown by the passed function value. This method invokes the passed function. If it throws an exception that's an instance of the passed class or one of its subclasses, this method returns that exception. Else, whether the passed function returns normally or completes abruptly with a different exception, this method throws TestFailedException whose detail message includes the String obtained by invoking toString on the passed message.
def intercept [T <: AnyRef](clazz : java.lang.Class[T])(f : => Any) : T
Deprecated: use the more concise version of intercept, which uses an implicit manifest. Intercept and return an instance of the passed exception class (or an instance of a subclass of the passed class), which is expected to be thrown by the passed function value. This method invokes the passed function. If it throws an exception that's an instance of the passed class or one of its subclasses, this method returns that exception. Else, whether the passed function returns normally or completes abruptly with a different exception, this method throws TestFailedException.
def intercept [T <: AnyRef](f : => Any)(implicit manifest : scala.reflect.Manifest[T]) : T
Intercept and return an exception that's expected to be thrown by the passed function value. The thrown exception must be an instance of the type specified by the type parameter of this method. This method invokes the passed function. If the function throws an exception that's an instance of the specified type, this method returns that exception. Else, whether the passed function returns normally or completes abruptly with a different exception, this method throws TestFailedException.
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Class Summary
class Equalizer (left : Any) extends AnyRef
Class used via an implicit conversion to enable any two objects to be compared with === in assertions in tests. For example:
   assert(a === b)
   
Method Details
def assert(condition : Boolean) : Unit
Assert that a boolean condition is true. If the condition is true, this method returns normally. Else, it throws TestFailedException.
Parameters
condition - the boolean condition to assert
Throws
TestFailedException - if the condition is false.

def assert(condition : Boolean, message : Any) : Unit
Assert that a boolean condition, described in String message, is true. If the condition is true, this method returns normally. Else, it throws TestFailedException with the String obtained by invoking toString on the specified message as the exception's detail message.
Parameters
condition - the boolean condition to assert
message - An objects whose toString method returns a message to include in a failure report.
Throws
TestFailedException - if the condition is false.
NullPointerException - if message is null.

def assert(o : scala.Option[java.lang.String], message : Any) : Unit
Assert that an Option[String] is None. If the condition is None, this method returns normally. Else, it throws TestFailedException with the String value of the Some, as well as the String obtained by invoking toString on the specified message, included in the TestFailedException's detail message.

This form of assert is usually called in conjunction with an implicit conversion to Equalizer, using a === comparison, as in:

   assert(a === b, "extra info reported if assertion fails")
   

For more information on how this mechanism works, see the documentation for Equalizer.

Parameters
o - the Option[String] to assert
message - An objects whose toString method returns a message to include in a failure report.
Throws
TestFailedException - if the Option[String] is Some.
NullPointerException - if message is null.

def assert(o : scala.Option[java.lang.String]) : Unit
Assert that an Option[String] is None. If the condition is None, this method returns normally. Else, it throws TestFailedException with the String value of the Some included in the TestFailedException's detail message.

This form of assert is usually called in conjunction with an implicit conversion to Equalizer, using a === comparison, as in:

   assert(a === b)
   

For more information on how this mechanism works, see the documentation for Equalizer.

Parameters
o - the Option[String] to assert
Throws
TestFailedException - if the Option[String] is Some.

implicit def convertToEqualizer(left : Any) : Equalizer
Implicit conversion from Any to Equalizer, used to enable assertions with === comparisons. For more information on this mechanism, see the documentation for Equalizer.
Parameters
left - the object whose type to convert to Equalizer.
Throws
NullPointerException - if left is null.

@scala.deprecated

def intercept[T <: AnyRef](clazz : java.lang.Class[T], message : Any)(f : => Any) : T
Deprecated: use the more concise version of intercept, which uses an implicit manifest. Note: there is currently no version of the "implicit manifest" form of intercept that takes a string message. The reason is it won't overload while these older forms are still in the API. Once these deprecated forms are removed, an overloaded version of intercept that takes a string message and implicit manifest will be added. Intercept and return an instance of the passed exception class (or an instance of a subclass of the passed class), which is expected to be thrown by the passed function value. This method invokes the passed function. If it throws an exception that's an instance of the passed class or one of its subclasses, this method returns that exception. Else, whether the passed function returns normally or completes abruptly with a different exception, this method throws TestFailedException whose detail message includes the String obtained by invoking toString on the passed message.

Note that the passed Class may represent any type, not just Throwable or one of its subclasses. In Scala, exceptions can be caught based on traits they implement, so it may at times make sense to pass in a class instance for a trait. If a class instance is passed for a type that could not possibly be used to catch an exception (such as String, for example), this method will complete abruptly with a TestFailedException.

Parameters
clazz - a type to which the expected exception class is assignable, i.e., the exception should be an instance of the type represented by clazz.
message - An objects whose toString method returns a message to include in a failure report.
f - the function value that should throw the expected exception
Returns
the intercepted exception, if
Throws
TestFailedException - if the passed function does not result in a value equal to the passed expected value.

@scala.deprecated

def intercept[T <: AnyRef](clazz : java.lang.Class[T])(f : => Any) : T
Deprecated: use the more concise version of intercept, which uses an implicit manifest. Intercept and return an instance of the passed exception class (or an instance of a subclass of the passed class), which is expected to be thrown by the passed function value. This method invokes the passed function. If it throws an exception that's an instance of the passed class or one of its subclasses, this method returns that exception. Else, whether the passed function returns normally or completes abruptly with a different exception, this method throws TestFailedException.

Note that the passed Class may represent any type, not just Throwable or one of its subclasses. In Scala, exceptions can be caught based on traits they implement, so it may at times make sense to pass in a class instance for a trait. If a class instance is passed for a type that could not possibly be used to catch an exception (such as String, for example), this method will complete abruptly with a TestFailedException.

Parameters
clazz - a type to which the expected exception class is assignable, i.e., the exception should be an instance of the type represented by clazz.
f - the function value that should throw the expected exception
Returns
the intercepted exception, if
Throws
TestFailedException - if the passed function does not complete abruptly with an exception that is assignable to the passed Class.
IllegalArgumentException - if the passed clazz is not Throwable or one of its subclasses.

def intercept[T <: AnyRef](f : => Any)(implicit manifest : scala.reflect.Manifest[T]) : T
Intercept and return an exception that's expected to be thrown by the passed function value. The thrown exception must be an instance of the type specified by the type parameter of this method. This method invokes the passed function. If the function throws an exception that's an instance of the specified type, this method returns that exception. Else, whether the passed function returns normally or completes abruptly with a different exception, this method throws TestFailedException.

Note that the type specified as this method's type parameter may represent any subtype of AnyRef, not just Throwable or one of its subclasses. In Scala, exceptions can be caught based on traits they implement, so it may at times make sense to specify a trait that the intercepted exception's class must mix in. If a class instance is passed for a type that could not possibly be used to catch an exception (such as String, for example), this method will complete abruptly with a TestFailedException.

Parameters
f - the function value that should throw the expected exception
manifest - an implicit Manifest representing the type of the specified type parameter.
Returns
the intercepted exception, if it is of the expected type
Throws
TestFailedException - if the passed function does not complete abruptly with an exception that's an instance of the specified type passed expected value.

def expect(expected : Any, message : Any)(actual : Any) : Unit
Expect that the value passed as expected equals the value passed as actual. If the actual equals the expected (as determined by ==), expect returns normally. Else, if actual is not equal to expected, expect throws an TestFailedException whose detail message includes the expected and actual values, as well as the String obtained by invoking toString on the passed message.
Parameters
expected - the expected value
message - An object whose toString method returns a message to include in a failure report.
actual - the actual value, which should equal the passed expected value
Throws
TestFailedException - if the passed actual value does not equal the passed expected value.

def expect(expected : Any)(actual : Any) : Unit
Expect that the value passed as expected equals the value passed as actual. If the actual value equals the expected value (as determined by ==), expect returns normally. Else, expect throws an TestFailedException whose detail message includes the expected and actual values.
Parameters
expected - the expected value
actual - the actual value, which should equal the passed expected value
Throws
TestFailedException - if the passed actual value does not equal the passed expected value.

def fail : Nothing
Throws TestFailedException to indicate a test failed.

def fail(message : java.lang.String) : Nothing
Throws TestFailedException, with the passed String message as the exception's detail message, to indicate a test failed.
Parameters
message - A message describing the failure.
Throws
NullPointerException - if message is null

def fail(message : java.lang.String, cause : java.lang.Throwable) : Nothing
Throws TestFailedException, with the passed String message as the exception's detail message and Throwable cause, to indicate a test failed.
Parameters
message - A message describing the failure.
cause - A Throwable that indicates the cause of the failure.
Throws
NullPointerException - if message or cause is null

def fail(cause : java.lang.Throwable) : Nothing
Throws TestFailedException, with the passed Throwable cause, to indicate a test failed. The getMessage method of the thrown TestFailedException will return cause.toString().
Parameters
cause - a Throwable that indicates the cause of the failure.
Throws
NullPointerException - if cause is null


Copyright (C) 2001-2009 Artima, Inc. All rights reserved.