forked from pepinns/go-hamcrest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hasmethod_test.go
63 lines (53 loc) · 1.85 KB
/
hasmethod_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package hamcrest_test
import (
"testing"
. "github.com/pepinns/go-hamcrest"
)
type TestObjectWithGetMethod struct {
ValueToReturn string
}
func (me *TestObjectWithGetMethod) GetValue() string {
return me.ValueToReturn
}
func (me *TestObjectWithGetMethod) GetTwoValues() (string, string) {
return me.ValueToReturn, "TestSecondValue"
}
type TestInterfaceForGetMethod interface {
GetValue() string
GetTwoValues() (string, string)
}
func TestHasMethodCanAssertValueOfGetMethods(t *testing.T) {
var tt TestInterfaceForGetMethod
tt = &TestObjectWithGetMethod{"TestObjectValue"}
Assert(t).That(tt, HasMethodThatReturns("GetValue", "TestObjectValue"))
}
func TestHasMethodCanAssertMultipleReturnValuesOfGetMethods(t *testing.T) {
// var tt TestInterfaceForGetMethod
tt := &TestObjectWithGetMethod{"TestObjectValue"}
Assert(t).That(tt, HasMethodThatReturns("GetTwoValues", "TestObjectValue", "TestSecondValue"))
}
func TestHasMethodResponseIsClear(t *testing.T) {
AssertFailureMessage(t, &TestObjectWithGetMethod{"TestValue"}, HasMethodThatReturns("GetValue", "TestValue"), Contains(`matched [GetValue:<TestValue>] because "GetValue" is equal to "GetValue" and`, `"TestValue" is equal to "TestValue"`))
}
func TestHasMethodResponseIsClearWhenTwoReturnValues(t *testing.T) {
AssertFailureMessage(t, &TestObjectWithGetMethod{"TestValue"}, HasMethodThatReturns("GetTwoValues", "TestValue", "TestSecondValue"), Contains(`is equal to "TestSecondValue"`))
}
type testVal struct {
Value string
}
type testValMethod struct {
val *testVal
val2 *testVal
}
func (me *testValMethod) Funcy() (*testVal, *testVal) {
return me.val, me.val2
}
func TestCanMatchHasFieldAfterHasMethod(t *testing.T) {
tt := &testValMethod{&testVal{"value"}, &testVal{"value2"}}
Assert(t).That(tt,
HasMethodThatReturns("Funcy",
HasField("Value", "value"),
HasField("Value", "value2"),
),
)
}