-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhamcrest_implements_test.go
48 lines (42 loc) · 1.09 KB
/
hamcrest_implements_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
package assert
import "testing"
type TestInterface interface {
Print()
}
type TestObjectWithoutPrint struct{}
type TestObjectWithPrint struct{}
func (*TestObjectWithPrint) Print() {}
func TestImplements(t *testing.T) {
{
var i *TestInterface = nil
value := new(TestObjectWithPrint)
err := AssertThat(value, Implements(i))
if err != nil {
t.Fatal("shouldn't return error")
}
}
{
var i *TestInterface = nil
value := new(TestObjectWithoutPrint)
err := AssertThat(value, Implements(i))
if err == nil {
t.Fatal("should return error")
}
}
{
var i *TestInterface = nil
value := new(TestObjectWithoutPrint)
err := AssertThat(value, Implements(i))
if err.Error() != "expected type 'assert.TestInterface' but got '*assert.TestObjectWithoutPrint'" {
t.Fatal("errormessage is incorrect")
}
}
{
var i *TestInterface = nil
value := new(TestObjectWithoutPrint)
err := AssertThat(value, Implements(i).Message("msg"))
if err.Error() != "msg, expected type 'assert.TestInterface' but got '*assert.TestObjectWithoutPrint'" {
t.Fatal("errormessage is incorrect")
}
}
}