3
import groovy.mock.GroovyMock
4
import junit.framework.AssertionFailedError
6
class MockTest extends GroovyTestCase {
11
mock = GroovyMock.newInstance()
14
void testASimpleExpectationCanBeSetAndMet() {
16
mock.doSomething("hello")
19
mock.instance.doSomething("hello")
25
void testASimpleExpectationCanBeSetAndFailed() {
27
mock.doSomething("hello")
31
mock.instance.doSomething("goodbye")
32
fail("expected exception")
34
catch (RuntimeException goodException) {
39
void testASimpleExpectationCanBeSetButNeverCalledSoVerifyFails() {
41
mock.doSomething("hello")
49
fail("should not have verified")
51
catch (AssertionFailedError goodException) {
55
void testAnExpectationWithAClosureGivesErrorIFCalledAndClosureFails() {
56
mock.doSomething( {arg -> assert arg=="poo" } )
60
mock.instance.doSomething("hello")
61
fail("Expected verify to fail");
63
catch (RuntimeException ex) {
71
void testAnExpectationwithAClosurePassesIfClosurePasses() {
72
mock.doSomething {arg -> assert arg=="hello" }
75
mock.instance.doSomething("hello")
81
void testAnExpectationWithAClosureGivesErrorIFNotCalled() {
82
mock.doSomething( {arg -> assert arg=="poo" } )
86
fail("Expected verify to fail");
88
catch (AssertionFailedError ex) {