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

org.scalatestexamples.fixture.suite.CaseClassFixtureSuite.scala Maven / Gradle / Ivy

There is a newer version: 2.0.M6-SNAP27
Show newest version
package org.scalatestexamples.fixture.suite

import org.scalatest.fixture
import scala.collection.mutable.ListBuffer

class CaseClassFixtureSuite extends fixture.Suite {

  case class FixtureHolder(builder: StringBuilder, buffer: ListBuffer[String])

  type FixtureParam = FixtureHolder

  def withFixture(test: OneArgTest) {

    // Create needed mutable objects
    val stringBuilder = new StringBuilder("ScalaTest is ")
    val listBuffer = new ListBuffer[String]

    // Invoke the test function, passing in the mutable objects
    test(FixtureHolder(stringBuilder, listBuffer))
  }

  def testEasy(fixture: FixtureParam) {
    import fixture._
    builder.append("easy!")
    assert(builder.toString === "ScalaTest is easy!")
    assert(buffer.isEmpty)
    buffer += "sweet"
  }

  def testFun(fixture: FixtureParam) {
    fixture.builder.append("fun!")
    assert(fixture.builder.toString === "ScalaTest is fun!")
    assert(fixture.buffer.isEmpty)
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy