| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 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 |
|
| 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 |
} |