Typeclass that enables for aggregations certain contain
syntax in the ScalaTest matchers DSL.
Supertrait for typeclasses that enable loneElement
and inspectors syntax
for collections.
Supertrait for typeclasses that enable loneElement
and inspectors syntax
for collections.
A Collecting[E, C]
provides access to the "collecting nature" of type C
in such
a way that loneElement
syntax can be used with type C
. A C
can be any type of "collecting", a type that in some way collects or brings together elements of type E
.
ScalaTest provides implicit implementations for several types. You can enable the contain
matcher syntax
on your own type U
by defining an Collecting[E, U]
for the type and making it available implicitly.
ScalaTest provides implicit Collecting
instances for scala.collection.GenTraversable
,
Array
, java.util.Collection
and java.util.Map
in the
Collecting
companion object.
Supertrait for typeclasses that enable certain contain
matcher syntax for containers.
Supertrait for typeclasses that enable certain contain
matcher syntax for containers.
A Containing[C]
provides access to the "containing nature" of type C
in such
a way that relevant contain
matcher syntax can be used with type C
. A C
can be any type of "container," a type that in some way can contains one or more other objects. ScalaTest provides
implicit implementations for several types. You can enable the contain
matcher syntax on your own
type U
by defining an Containing[U]
for the type and making it available implicitly.
ScalaTest provides implicit Containing
instances for scala.collection.GenTraversable
,
java.util.Collection
, java.util.Map
, String
, Array
,
and scala.Option
in the Containing
companion object.
Containing
versus Aggregating
The difference between Containing
and Aggregating
is that
Containing
enables contain
matcher syntax that makes sense for "box" types that can
contain at most one value (for example, scala.Option
),
whereas Aggregating
enables contain
matcher syntax for full-blown collections and other
aggregations of potentially more than one object. For example, it makes sense to make assertions like these, which
are enabled by Containing
, for scala.Option
:
val option: Option[Int] = Some(7) option should contain (7) option should contain oneOf (6, 7, 8) option should contain noneOf (3, 4, 5)
However, given a scala.Option
can only ever contain at most one object, it doesn't make
sense to make assertions like the following, which are enabled via Aggregation
:
// Could never succeed, so does not compile option should contain allOf (6, 7, 8)
The above assertion could never succceed, because an option cannot contain more than
one value. By default the above statement does not compile, because contain
allOf
is enabled by Aggregating
, and ScalaTest provides no implicit Aggregating
instance
for type scala.Option
.
Supertrait for typeclasses that enable the be defined
matcher syntax.
Supertrait for typeclasses that enable the be defined
matcher syntax.
A Definition[T]
provides access to the "definition nature" of type S
in such
a way that be defined
matcher syntax can be used with type T
. A T
can be any type for which the concept of being defined makes sense, such as scala.Option
. ScalaTest provides
implicit implementation for scala.Option
. You can enable the be defined
matcher syntax on your own
type U
by defining a Definition[U]
for the type and making it available implicitly.
ScalaTest provides an implicit Definition
instance for scala.Option
,
arbitary object with isDefined()
or isDefined
in the Definition
companion object.
Supertrait for typeclasses that enable be empty
matcher syntax.
Supertrait for typeclasses that enable be empty
matcher syntax.
An Emptiness[T]
provides access to the "emptiness" of type T
in such
a way that be empty
matcher syntax can be used with type T
. A T
can be any type that in some way can be empty. ScalaTest provides implicit implementations for several types.
You can enable the be empty
matcher syntax on your own type U
by defining an Emptiness[U]
for the type and making it available implicitly.
ScalaTest provides implicit Emptiness
instances for scala.collection.GenTraversable
,
java.util.Collection
, java.util.Map
, String
, Array
,
and scala.Option
in the Emptiness
companion object.
Supertrait for typeclasses that enable the exist
matcher syntax.
Supertrait for typeclasses that enable the exist
matcher syntax.
An Existence[S]
provides access to the "existence nature" of type S
in such
a way that exist
matcher syntax can be used with type S
. A S
can be any type for which the concept of existence makes sense, such as java.io.File
. ScalaTest provides
implicit implementations for java.io.File
. You can enable the exist
matcher syntax on your own
type U
by defining a Existence[U]
for the type and making it available implicitly.
ScalaTest provides an implicit Existence
instance for java.io.File
in the Existence
companion object.
Supertrait for typeclasses that enable contain key
matcher syntax.
Supertrait for typeclasses that enable contain key
matcher syntax.
A KeyMapping[M]
provides access to the "key mapping nature" of type M
in such
a way that contain key
matcher syntax can be used with type M
. A M
can be any type for which contain key
syntax makes sense. ScalaTest provides implicit implementations
for scala.collection.GenMap
and java.util.Map
. You can enable the contain key
matcher syntax on your own type U
by defining a KeyMapping[U]
for the type and making it
available implicitly.
ScalaTest provides implicit KeyMapping
instances for scala.collection.GenMap
,
and java.util.Map
in the KeyMapping
companion object.
Supertrait for Length
typeclasses.
Supertrait for Length
typeclasses.
Trait Length
is a typeclass trait for objects that can be queried for length.
Objects of type T for which an implicit Length[T]
is available can be used
with the should have length
syntax.
In other words, this trait enables you to use the length checking
syntax with arbitrary objects. As an example, consider
java.net.DatagramPacket
, which has a getLength
method. By default, this
can't be used with ScalaTest's have length
syntax.
scala> import java.net.DatagramPacket import java.net.DatagramPacket scala> import org.scalatest.Matchers._ import org.scalatest.Matchers._ scala> val dp = new DatagramPacket(Array(0x0, 0x1, 0x2, 0x3), 4) dp: java.net.DatagramPacket = java.net.DatagramPacket@54906181 scala> dp.getLength res0: Int = 4 scala> dp should have length 4:13: error: could not find implicit value for parameter ev: org.scalatest.matchers.ShouldMatchers.Extent[java.net.DatagramPacket] dp should have length 4 ^ scala> implicit val lengthOfDatagramPacket = | new Length[DatagramPacket] { | def lengthOf(dp: DatagramPacket): Long = dp.getLength | } lengthOfDatagramPacket: java.lang.Object with org.scalatest.matchers.ShouldMatchers.Length[java.net.DatagramPacket] = $anon$1@550c6b37 scala> dp should have length 4 scala> dp should have length 3 org.scalatest.exceptions.TestFailedException: java.net.DatagramPacket@54906181 had length 4, not length 3
Supertrait for Messaging
typeclasses.
Supertrait for Messaging
typeclasses.
Trait Messaging
is a typeclass trait for objects that can be queried for message.
Objects of type T for which an implicit Messaging[T]
is available can be used
with the should have message
syntax.
You can enable the have message
matcher syntax on your own
type U
by defining a Messaging[U]
for the type and making it available implicitly.
ScalaTest provides an implicit Messaging
instance for java.lang.Throwable
and
arbitary object with message()
, message
, getMessage()
or getMessage
method in the Messaging
companion object.
Supertrait for typeclasses that enable the be readable
matcher syntax.
Supertrait for typeclasses that enable the be readable
matcher syntax.
A Readability[T]
provides access to the "readable nature" of type T
in such
a way that be readable
matcher syntax can be used with type T
. A T
can be any type for which the concept of being readable makes sense, such as java.io.File
.
You can enable the be readable
matcher syntax on your own type U
by defining a
Readability[U]
for the type and making it available implicitly.
ScalaTest provides an implicit Readability
instance for java.io.File
and arbitary
object with isReadable()
or isReadable
in the Readability
companion object.
Typeclass that enables for sequencing certain contain
syntax in the ScalaTest matchers DSL.
Typeclass that enables for sequencing certain contain
syntax in the ScalaTest matchers DSL.
An Sequencing[A]
provides access to the "sequenching nature" of type A
in such
a way that relevant contain
matcher syntax can be used with type A
. An A
can be any type of sequencing—an object that in some way brings together other objects in order.
ScalaTest provides implicit implementations for several types out of the box in the
Sequencing
companion object:
scala.collection.GenSeq
scala.collection.SortedSet
scala.collection.SortedMap
Array
java.util.List
java.util.SortedSet
java.util.SortedMap
String
The contain
syntax enabled by this trait is:
result should contain inOrder (1, 2, 3)
result should contain inOrderOnly (1, 2, 3)
result should contain theSameElementsInOrderAs List(1, 2, 3)
You can enable the contain
matcher syntax enabled by Sequencing
on your own
type U
by defining an Sequencing[U]
for the type and making it available implicitly.
Supertrait for Size
typeclasses.
Supertrait for Size
typeclasses.
Trait Size
is a typeclass trait for objects that can be queried for size.
Objects of type T for which an implicit Size[T]
is available can be used
with the should have size
syntax.
In other words, this trait enables you to use the size checking
syntax with arbitrary objects. As an example, consider
java.net.DatagramPacket
, which has a getSize
method. By default, this
can't be used with ScalaTest's have size
syntax.
scala> import java.awt.image.DataBufferByte import java.awt.image.DataBufferByte scala> import org.scalatest.matchers.ShouldMatchers._ import org.scalatest.matchers.ShouldMatchers._ scala> val db = new DataBufferByte(4) db: java.awt.image.DataBufferByte = java.awt.image.DataBufferByte@33d5e94f scala> db.getSize res0: Int = 4 scala> db should have size 4:17: error: could not find implicit value for parameter ev: org.scalatest.matchers.ShouldMatchers.Extent[java.awt.image.DataBufferByte] db should have size 4 ^ scala> implicit val sizeOfDataBufferByte = | new Size[DataBufferByte] { | def sizeOf(db: DataBufferByte): Long = db.getSize | } sizeOfDataBufferByte: java.lang.Object with org.scalatest.matchers.ShouldMatchers.Size[java.awt.image.DataBufferByte] = $anon$1@4c69bdf8 scala> db should have size 4 scala> db should have size 3 org.scalatest.exceptions.TestFailedException: java.awt.image.DataBufferByte@33d5e94f had size 4, not size 3
Supertrait for typeclasses that enable the be
sorted
matcher syntax.
Supertrait for typeclasses that enable the be
sorted
matcher syntax.
A Sortable[S]
provides access to the "sortable nature" of type S
in such
a way that be
sorted
matcher syntax can be used with type S
. An S
can be any type for which the concept of being sorted makes sense, such as sequences. ScalaTest provides
implicit implementations for several types. You can enable the be
sorted
matcher syntax on your own
type U
by defining a Sortable[U]
for the type and making it available implicitly.
ScalaTest provides an implicit Sortable
instance for types out of the box
in the Sortable
companion object:
scala.collection.GenSeq
Array
java.util.List
Supertrait for typeclasses that enable contain value
matcher syntax.
Supertrait for typeclasses that enable contain value
matcher syntax.
A ValueMapping[M]
provides access to the "value mapping nature" of type M
in such
a way that contain
value
matcher syntax can be used with type M
. An M
can be any type for which contain
value
syntax makes sense. ScalaTest provides implicit implementations
for scala.collection.GenMap
and java.util.Map
. You can enable the contain
value
matcher syntax on your own type U
by defining a ValueMapping[U]
for the type and making it
available implicitly.
ScalaTest provides implicit ValueMapping
instances for scala.collection.GenMap
,
and java.util.Map
in the ValueMapping
companion object.
Supertrait for typeclasses that enable the be
writable
matcher syntax.
Supertrait for typeclasses that enable the be
writable
matcher syntax.
A Writability[T]
provides access to the "writable nature" of type T
in such
a way that be
writable
matcher syntax can be used with type T
. A T
can be any type for which the concept of being writable makes sense, such as java.io.File
. ScalaTest provides
implicit implementation for java.io.File
. You can enable the be
writable
matcher syntax on your own
type U
by defining a Writability[U]
for the type and making it available implicitly.
ScalaTest provides an implicit Writability
instance for java.io.File
and arbitary
object with isWritable()
or isWritable
in the Writability
companion object.
Companion object for Aggregating
that provides implicit implementations for the following types:
Companion object for Aggregating
that provides implicit implementations for the following types:
scala.collection.GenTraversable
String
Array
java.util.Collection
java.util.Map
Companion object for Collecting
that provides implicit implementations for the following types:
Companion object for Collecting
that provides implicit implementations for the following types:
scala.collection.GenTraversable
Array
java.util.Collection
java.util.Map
Companion object for Containing
that provides implicit implementations for the following types:
Companion object for Containing
that provides implicit implementations for the following types:
scala.collection.GenTraversable
String
Array
scala.Option
java.util.Collection
java.util.Map
Companion object for Definition
that provides implicit implementations for the following types:
Companion object for Definition
that provides implicit implementations for the following types:
scala.Option
isDefined()
method that returns Boolean
isDefined
method that returns Boolean
Companion object for Emptiness
that provides implicit implementations for the following types:
Companion object for Emptiness
that provides implicit implementations for the following types:
scala.collection.GenTraversable
String
Array
scala.Option
java.util.Collection
java.util.Map
isEmpty()
method that returns Boolean
isEmpty
method that returns Boolean
Companion object for Existence
that provides implicit implementations for java.io.File
.
Companion object for Existence
that provides implicit implementations for java.io.File
.
Companion object for KeyMapping
that provides implicit implementations for scala.collection.GenMap
and java.util.Map
.
Companion object for KeyMapping
that provides implicit implementations for scala.collection.GenMap
and java.util.Map
.
Companion object for Length
that provides implicit implementations for the following types:
Companion object for Length
that provides implicit implementations for the following types:
scala.collection.GenSeq
String
Array
java.util.Collection
length()
method that returns Int
length
method that returns Int
getLength()
method that returns Int
getLength
method that returns Int
length()
method that returns Long
length
method that returns Long
getLength()
method that returns Long
getLength
method that returns Long
Companion object for Messaging
that provides implicit implementations for the following types:
Companion object for Messaging
that provides implicit implementations for the following types:
java.lang.Throwable
message()
method that returns String
message
method that returns String
getMessage()
method that returns String
getMessage
method that returns String
Companion object for Readability
that provides implicit implementations for the following types:
Companion object for Readability
that provides implicit implementations for the following types:
java.io.File
isReadable()
method that returns Boolean
isReadable
method that returns Boolean
Companion object for Sequencing
that provides implicit implementations for the following types:
Companion object for Sequencing
that provides implicit implementations for the following types:
scala.collection.GenSeq
scala.collection.SortedSet
scala.collection.SortedMap
Array
java.util.List
java.util.SortedSet
java.util.SortedMap
String
Companion object for Length
that provides implicit implementations for the following types:
Companion object for Length
that provides implicit implementations for the following types:
scala.collection.GenTraversable
String
Array
java.util.Collection
java.util.Map
size()
method that returns Int
size
method that returns Int
getSize()
method that returns Int
getSize
method that returns Int
size()
method that returns Long
size
method that returns Long
getSize()
method that returns Long
getSize
method that returns Long
Companion object for Sortable
that provides implicit implementations for the following types:
Companion object for Sortable
that provides implicit implementations for the following types:
scala.collection.GenSeq
Array
java.util.List
Companion object for ValueMapping
that provides implicit implementations for scala.collection.GenMap
and java.util.Map
.
Companion object for ValueMapping
that provides implicit implementations for scala.collection.GenMap
and java.util.Map
.
Companion object for Writability
that provides implicit implementations for the following types:
Companion object for Writability
that provides implicit implementations for the following types:
java.io.File
isWritable()
method that returns Boolean
isWritable
method that returns Boolean
Typeclass that enables for aggregations certain
contain
syntax in the ScalaTest matchers DSL.An
Aggregating[A]
provides access to the "aggregating nature" of typeA
in such a way that relevantcontain
matcher syntax can be used with typeA
. AnA
can be any type of aggregation—an object that in some way aggregates or brings together other objects. ScalaTest provides implicit implementations for several types out of the box in theAggregating
companion object:scala.collection.GenTraversable
String
Array
java.util.Collection
java.util.Map
The
contain
syntax enabled by this trait is:result
should
contain
atLeastOneOf
(1, 2, 3)
result
should
contain
atMostOneOf
(1, 2, 3)
result
should
contain
only
(1, 2, 3)
result
should
contain
allOf
(1, 2, 3)
result
should
contain
theSameElementsAs
(List(1, 2, 3))
You can enable the
contain
matcher syntax enabled byAggregating
on your own typeU
by defining anAggregating[U]
for the type and making it available implicitly.Note, for an explanation of the difference between
Containing
andAggregating
, both of which enablecontain
matcher syntax, see the Containing versus Aggregating section of the main documentation for traitContaining
.