org.scalatest.Assertions

Equalizer

class Equalizer 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)

The benefit of using assert(a === b) rather than assert(a == b) is that a TestFailedException produced by the former will include the values of a and bin its detail message. The implicit method that performs the conversion from Any to Equalizer isconvertToEqualizer in trait Assertions.

In case you're not familiar with how implicit conversions work in Scala, here's a quick explanation. The convertToEqualizer method in Assertions is defined as an "implicit" method that takes anAny, which means you can pass in any object, and it will convert it to an Equalizer. The Equalizer has === defined. Most objects don't have === defined as a method on them. Take two Strings, for example:

assert("hello" === "world")

Given this code, the Scala compiler looks for an === method on class String, because that's the class of"hello". String doesn't define ===, so the compiler looks for an implicit conversion fromString to something that does have an === method, and it finds the convertToEqualizer method. It then rewrites the code to this:

assert(convertToEqualizer("hello").===("world"))

So inside a Suite (which mixes in Assertions, === will work on anything. The only situation in which the implicit conversion wouldn't happen is on types that have an === method already defined.

The primary constructor takes one object, left, whose type is being converted to Equalizer. The leftvalue may be a null reference, because this is allowed by Scala's == operator.

attributes: final
    authors:
  1. Bill Venners

Inherited
  1. Hide All
  2. Show all
  1. AnyRef
  2. Any
Visibility
  1. Public
  2. All

Instance constructors

  1. new Equalizer(left: Any)

Value Members

  1. def !=(arg0: AnyRef): Boolean

  2. def !=(arg0: Any): Boolean

    o != arg0 is the same as !(o == (arg0)).

  3. def ##(): Int

  4. def $asInstanceOf[T0](): T0

  5. def $isInstanceOf[T0](): Boolean

  6. def ==(arg0: AnyRef): Boolean

    o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).

  7. def ==(arg0: Any): Boolean

    o == arg0 is the same as o.equals(arg0).

  8. def ===(right: Any): Option[String]

    The === operation compares this Equalizer's left value (passed to the constructor, usually via an implicit conversion) with the passed right value for equality as determined by the expression left == right.

  9. def asInstanceOf[T0]: T0

    This method is used to cast the receiver object to be of type T0.

  10. def clone(): AnyRef

    This method creates and returns a copy of the receiver object.

  11. def eq(arg0: AnyRef): Boolean

    This method is used to test whether the argument (arg0) is a reference to the receiver object (this).

  12. def equals(arg0: Any): Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

  13. def finalize(): Unit

    This method is called by the garbage collector on the receiver object when garbage collection determines that there are no more references to the object.

  14. def getClass(): java.lang.Class[_]

    Returns a representation that corresponds to the dynamic class of the receiver object.

  15. def hashCode(): Int

    Returns a hash code value for the object.

  16. def isInstanceOf[T0]: Boolean

    This method is used to test whether the dynamic type of the receiver object is T0.

  17. def ne(arg0: AnyRef): Boolean

    o.ne(arg0) is the same as !(o.eq(arg0)).

  18. def notify(): Unit

    Wakes up a single thread that is waiting on the receiver object's monitor.

  19. def notifyAll(): Unit

    Wakes up all threads that are waiting on the receiver object's monitor.

  20. def synchronized[T0](arg0: T0): T0

  21. def toString(): String

    Returns a string representation of the object.

  22. def wait(): Unit

  23. def wait(arg0: Long, arg1: Int): Unit

  24. def wait(arg0: Long): Unit