~ubuntu-branches/ubuntu/lucid/groovy/lucid

« back to all changes in this revision

Viewing changes to src/test/groovy/mock/MockTest.groovy

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath, Torsten Werner, Varun Hiremath
  • Date: 2009-04-01 19:24:19 UTC
  • mfrom: (3.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090401192419-c5mpylqhcdkv3zuv
Tags: 1.6.0-1
[ Torsten Werner ]
* New upstream release (Closes: #521648)
* Remove Build-Depends: libclassworlds-java.
* Switch to source and target version 1.5.

[ Varun Hiremath ]
* Fix build.xml file
* Add ivy to Build-Depends
* Remove unnecessary Depends -- collections3, mx4j and xpp3 
* Add build.diff patch to fix a build error
* Use quilt to manage patches
* Update manpage (Closes: #507862)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package groovy.mock
2
 
 
3
 
import groovy.mock.GroovyMock
4
 
import junit.framework.AssertionFailedError
5
 
 
6
 
class MockTest extends GroovyTestCase {
7
 
 
8
 
    def mock
9
 
 
10
 
    void setUp() {
11
 
        mock = GroovyMock.newInstance()
12
 
    }
13
 
 
14
 
    void testASimpleExpectationCanBeSetAndMet() {
15
 
        // expectation
16
 
        mock.doSomething("hello")
17
 
 
18
 
        // execute
19
 
        mock.instance.doSomething("hello")
20
 
 
21
 
        // verify
22
 
        mock.verify()
23
 
    }
24
 
 
25
 
    void testASimpleExpectationCanBeSetAndFailed() {
26
 
        // expectation
27
 
        mock.doSomething("hello")
28
 
 
29
 
        // execute
30
 
        try {
31
 
            mock.instance.doSomething("goodbye")
32
 
            fail("expected exception")
33
 
        }
34
 
        catch (RuntimeException goodException) {
35
 
        }
36
 
 
37
 
    }
38
 
 
39
 
    void testASimpleExpectationCanBeSetButNeverCalledSoVerifyFails() {
40
 
        // expectation
41
 
        mock.doSomething("hello")
42
 
 
43
 
        // execute
44
 
        // don't call it
45
 
 
46
 
        // verify
47
 
        try {
48
 
            mock.verify()
49
 
            fail("should not have verified")
50
 
        }
51
 
        catch (AssertionFailedError goodException) {
52
 
        }
53
 
    }
54
 
 
55
 
    void testAnExpectationWithAClosureGivesErrorIFCalledAndClosureFails() {
56
 
        mock.doSomething( {arg -> assert arg=="poo" } )
57
 
 
58
 
        // verify
59
 
        try {
60
 
            mock.instance.doSomething("hello")
61
 
            fail("Expected verify to fail");
62
 
        }
63
 
        catch (RuntimeException ex) {
64
 
            //expected
65
 
        }
66
 
    }
67
 
 
68
 
    /*
69
 
     * was GROOVY-76
70
 
     */
71
 
    void testAnExpectationwithAClosurePassesIfClosurePasses() {
72
 
        mock.doSomething {arg -> assert arg=="hello" }
73
 
 
74
 
        // execute
75
 
        mock.instance.doSomething("hello")
76
 
 
77
 
        //verify
78
 
        mock.verify()
79
 
    }
80
 
 
81
 
    void testAnExpectationWithAClosureGivesErrorIFNotCalled() {
82
 
        mock.doSomething( {arg -> assert arg=="poo" } )
83
 
        // verify
84
 
        try {
85
 
            mock.verify()
86
 
            fail("Expected verify to fail");
87
 
        }
88
 
        catch (AssertionFailedError ex) {
89
 
            //expected
90
 
        }
91
 
    }
92
 
 
93
 
}
94
 
 
95