All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalatest.GivenWhenThen.scala Maven / Gradle / Ivy

Go to download

ScalaTest is a free, open-source testing toolkit for Scala and Java programmers.

There is a newer version: 2.0.M6-SNAP4
Show newest version
/*
 * Copyright 2001-2008 Artima, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.scalatest

/**
 * Trait that contains methods named given, when, then, and and,
 * which take a string message and implicit Informer, and forward the message to the informer.
 *
 * 

* Here's an example: *

* *
 * package org.scalatest.examples.flatspec.info
 * 
 * import collection.mutable
 * import org.scalatest._
 * 
 * class SetSpec extends FlatSpec with GivenWhenThen {
 *   
 *   "A mutable Set" should "allow an element to be added" in {
 *     Given("an empty mutable Set")
 *     val set = mutable.Set.empty[String]
 * 
 *     When("an element is added")
 *     set += "clarity"
 * 
 *     Then("the Set should have size 1")
 *     assert(set.size === 1)
 * 
 *     And("the Set should contain the added element")
 *     assert(set.contains("clarity"))
 * 
 *     info("That's all folks!")
 *   }
 * }
 * 
* *

* If you run this FlatSpec from the interpreter, you will see the following output: *

* *
 * scala> new SetSpec execute
 * A mutable Set
 * - should allow an element to be added
 *   + Given an empty mutable Set 
 *   + When an element is added 
 *   + Then the Set should have size 1 
 *   + And the Set should contain the added element 
 *   + That's all folks! 
 * 
* *

* Note: The lower case forms of given, when, then and and were * deprecated in ScalaTest because using then as an identifier was deprecated in Scala 2.10. *

* * @author Bill Venners */ trait GivenWhenThen { /** *

* The lower case form of given was * deprecated because using then as an identifier was deprecated in Scala 2.10. * Please use the upper case form, Given, instead. *

*/ @deprecated("Please use Given(message: String)(implicit info: Informer) instead.") def given(message: String)(implicit info: Informer) { Given(message) } /** * Forwards a message to an implicit Informer, preceded by "Given." * * @param message the message to forward to the passed informer * @param info the Informer to which to forward the message */ def Given(message: String)(implicit info: Informer) { info(Resources("givenMessage", message)) } /** *

* The lower case form of when was * deprecated because using then as an identifier was deprecated in Scala 2.10. * Please use the upper case form, When, instead. *

*/ @deprecated("Please use When(message: String)(implicit info: Informer) instead.") def when(message: String)(implicit info: Informer) { When(message) } /** * Forwards a message to an implicit Informer, preceded by "When ". * * @param message the message to forward to the passed informer * @param info the Informer to which to forward the message */ def When(message: String)(implicit info: Informer) { info(Resources("whenMessage", message)) } /** *

* The lower case form of then was * deprecated because using then as an identifier was deprecated in Scala 2.10. * Please use the upper case form, Then, instead. *

*/ @deprecated("Please use Then(message: String)(implicit info: Informer) instead.") def then(message: String)(implicit info: Informer) { Then(message) } /** * Forwards a message to an implicit Informer, preceded by "Then ". * * @param message the message to forward to the passed informer * @param info the Informer to which to forward the message */ def Then(message: String)(implicit info: Informer) { info(Resources("thenMessage", message)) } /** *

* The lower case form of and was * deprecated because using then as an identifier was deprecated in Scala 2.10. * Please use the upper case form, And, instead. *

*/ @deprecated("Please use And(message: String)(implicit info: Informer) instead.") def and(message: String)(implicit info: Informer) { And(message) } /** * Forwards a message to an implicit Informer, preceded by "And ". * * @param message the message to forward to the passed informer * @param info the Informer to which to forward the message */ def And(message: String)(implicit info: Informer) { info(Resources("andMessage", message)) } } /** * Companion object that facilitates the importing of GivenWhenThen members as * an alternative to mixing it in. * * @author Bill Venners */ object GivenWhenThen extends GivenWhenThen





© 2015 - 2024 Weber Informatics LLC | Privacy Policy