Wrapper class that adds a loneElement
method to any collection type C
for which
an implicit Collecting[C]
is available.
Wrapper class that adds a loneElement
method to any collection type C
for which
an implicit Collecting[C]
is available.
Through the implicit conversion provided by trait LoneElement
, this class allows you to make statements like:
trav.loneElement should be > 9
the element type of the collection on which to add the loneElement
method
the "collection type constructor" for the collection on which to add the loneElement
method
Wrapper class that adds a loneElement
method to Java Map for which
an implicit Collecting[org.scalatest.Entry, java.util.Map]
is available.
Wrapper class that adds a loneElement
method to Java Map for which
an implicit Collecting[org.scalatest.Entry, java.util.Map]
is available.
Through the implicit conversion provided by trait LoneElement
, this class allows you to make statements like:
jmap.loneElement.getKey should be > 9
the element type of the Java Map key on which to add the loneElement
method
the element type of the Java Map value on which to add the loneElement
method
the "Java Map type constructor" for the collection on which to add the loneElement
method
Wrapper class that adds a loneElement
method to Map for which
an implicit Collecting[(K, V), scala.collection.GenTraversable[(K, V)]]
is available.
Wrapper class that adds a loneElement
method to Map for which
an implicit Collecting[(K, V), scala.collection.GenTraversable[(K, V)]]
is available.
Through the implicit conversion provided by trait LoneElement
, this class allows you to make statements like:
map.loneElement._1 should be > 9
the element type of the Map key on which to add the loneElement
method
the element type of the Map value on which to add the loneElement
method
the "Map type constructor" for the collection on which to add the loneElement
method
Wrapper class that adds a loneElement
method to String
for which an
implicit Collecting[C]
is available.
Wrapper class that adds a loneElement
method to String
for which an
implicit Collecting[C]
is available.
Through the implicit conversion provided by trait LoneElement
, this class allows you to make statements like:
"9".loneElement should be ('9')
Implicit conversion that adds a loneElement
method to any collection type C
for which an
implicit Collecting[C]
is available.
Implicit conversion that adds a loneElement
method to any collection type C
for which an
implicit Collecting[C]
is available.
the element type of the collection on which to add the loneElement
method
the "collection type constructor" for the collection on which to add the loneElement
method
the collection on which to add the loneElement
method
a typeclass that enables the loneElement
syntax
Implicit conversion that adds a loneElement
method to String for which an
implicit Collecting[C]
is available.
Implicit conversion that adds a loneElement
method to String for which an
implicit Collecting[C]
is available.
the String
to wrap
Trait that provides an implicit conversion that adds to collection types a
loneElement
method, which will return the value of the lone element if the collection does indeed contain one and only one element, or throwTestFailedException
if not.This construct allows you to express in one statement that a collection should contain one and only one element and that the element value should meet some expectation. Here's an example:
Or, using an assertion instead of a matcher expression:
The
loneElement
syntax can be used with any collection typeC
for which an implicitCollecting[C]
is available. ScalaTest provides implicitCollecting
instances forscala.collection.GenTraversable
,Array
, andjava.util.Collection
. You can enable theloneElement
syntax on other collection types by defining an implicitCollecting
instances for those types.If you want to use
loneElement
with ajava.util.Map
, first transform it to a set of entries withentrySet
, and if helpful, use ScalaTest'sEntry
class: