Debian Codegraph @

test_cases/mock.test.go

raw symbols SCIP
1 // Copyright 2011 Aaron Jacobs. All Rights Reserved.
2 // Author: [email protected] (Aaron Jacobs)
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
16 package oglematchers_test
17
18 import (
19 . "github.com/jacobsa/oglematchers"
20 "github.com/jacobsa/oglemock"
21 . "github.com/jacobsa/ogletest"
22 "github.com/jacobsa/ogletest/test_cases/mock_image"
23 "image/color"
24 "testing"
25 )
26
27 ////////////////////////////////////////////////////////////////////////
28 // Helpers
29 ////////////////////////////////////////////////////////////////////////
30
31 type MockTest struct {
32 controller oglemock.Controller
33 image mock_image.MockImage
34 }
35
36 func init() { RegisterTestSuite(&MockTest{}) }
37 func TestMockTest(t *testing.T) { RunTests(t) }
38
39 func (t *MockTest) SetUp(i *TestInfo) {
40 t.controller = i.MockController
41 t.image = mock_image.NewMockImage(t.controller, "some mock image")
42 }
43
44 ////////////////////////////////////////////////////////////////////////
45 // Tests
46 ////////////////////////////////////////////////////////////////////////
47
48 func (t *MockTest) ExpectationSatisfied() {
49 ExpectCall(t.image, "At")(11, GreaterThan(19)).
50 WillOnce(oglemock.Return(color.Gray{0}))
51
52 ExpectThat(t.image.At(11, 23), IdenticalTo(color.Gray{0}))
53 }
54
55 func (t *MockTest) MockExpectationNotSatisfied() {
56 ExpectCall(t.image, "At")(11, GreaterThan(19)).
57 WillOnce(oglemock.Return(color.Gray{0}))
58 }
59
60 func (t *MockTest) ExpectCallForUnknownMethod() {
61 ExpectCall(t.image, "FooBar")(11)
62 }
63
64 func (t *MockTest) UnexpectedCall() {
65 t.image.At(11, 23)
66 }
67
68 func (t *MockTest) InvokeFunction() {
69 var suppliedX, suppliedY int
70 f := func(x, y int) color.Color {
71 suppliedX = x
72 suppliedY = y
73 return color.Gray{17}
74 }
75
76 ExpectCall(t.image, "At")(Any(), Any()).
77 WillOnce(oglemock.Invoke(f))
78
79 ExpectThat(t.image.At(-1, 12), IdenticalTo(color.Gray{17}))
80 ExpectEq(-1, suppliedX)
81 ExpectEq(12, suppliedY)
82 }