1/* 2 * Copyright 2001-2008 Artima, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.scalatest.jmock 17 18import org.scalatest._ 19import scala.reflect.Manifest 20import org.jmock.Expectations 21import org.hamcrest.core.IsAnything 22import org.scalatest.events._ 23 24trait SuiteExpectations { 25 26 def expectSingleTestToPass(expectations: Expectations, reporter: Reporter) = expectNTestsToPass(expectations, 1, reporter) 27 def expectSingleTestToFail(expectations: Expectations, reporter: Reporter) = expectNTestsToFail(expectations, 1, reporter) 28 29 def expectNTestsToPass(expectations: Expectations, n: Int, reporter: Reporter) = { 30 expectNTestsToRun(expectations, n, reporter) { 31 expectations.one(reporter).apply(expectations.`with`(new IsAnything[TestSucceeded])) 32 } 33 } 34 35 def expectNTestsToFail(expectations: Expectations, n: Int, reporter: Reporter) = { 36 expectNTestsToRun(expectations, n, reporter) { 37 expectations.one(reporter).apply(expectations.`with`(new IsAnything[TestFailed])) 38 } 39 } 40 41 def expectNTestsToRun(expectations: Expectations, n: Int, reporter: Reporter)(f: => Unit) = { 42 expectations.one(reporter).apply(expectations.`with`(new IsAnything[SuiteStarting])) 43 for( i <- 1 to n ){ 44 expectations.one(reporter).apply(expectations.`with`(new IsAnything[TestStarting])) 45 f 46 } 47 expectations.one(reporter).apply(expectations.`with`(new IsAnything[SuiteCompleted])) 48 } 49} 50 51