-
Notifications
You must be signed in to change notification settings - Fork 0
/
component_test.go
102 lines (80 loc) · 2.35 KB
/
component_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package core
import (
"github.com/procyon-projects/goo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"testing"
)
type mockComponentProcessor struct {
mock.Mock
}
func newMockComponentProcessor() mockComponentProcessor {
return mockComponentProcessor{}
}
func (processor mockComponentProcessor) SupportsComponent(typ goo.Type) bool {
results := processor.Called(typ)
return results.Bool(0)
}
func (processor mockComponentProcessor) ProcessComponent(typ goo.Type) error {
results := processor.Called(typ)
return results.Error(0)
}
type testInterface interface {
test()
}
type testComponent struct {
}
func newTestComponent() testComponent {
return testComponent{}
}
func (testComponent) test() {
}
type testComponent2 struct {
}
func newTestComponentWithParam(str string) testComponent2 {
return testComponent2{}
}
func (testComponent2) test() {
}
func init() {
Register(newMockComponentProcessor)
Register(newTestComponent)
Register(newTestComponentWithParam)
}
func TestForEachComponentType(t *testing.T) {
count := 0
ForEachComponentType(func(componentName string, typ goo.Type) error {
count++
return nil
})
assert.Equal(t, 3, count)
}
func TestForEachComponentProcessor(t *testing.T) {
mockComponentProcessorType := goo.GetType(newMockComponentProcessor)
ForEachComponentProcessor(func(componentName string, typ goo.Type) error {
assert.Equal(t, "github.com.procyon.projects.procyon.core.mockComponentProcessor", componentName)
assert.True(t, mockComponentProcessorType.GetGoType() == typ.GetGoType())
return nil
})
}
func TestGetComponentTypes_WithNil(t *testing.T) {
_, err := GetComponentTypes(nil)
assert.NotNil(t, err)
assert.Equal(t, "type must not be null", err.Error())
}
func TestGetComponentTypes(t *testing.T) {
types, err := GetComponentTypes(goo.GetType(testComponent{}))
assert.Nil(t, err)
assert.Equal(t, 1, len(types))
types, err = GetComponentTypes(goo.GetType((*testInterface)(nil)))
assert.Nil(t, err)
assert.Equal(t, 1, len(types))
}
func TestGetComponentTypesWithParam(t *testing.T) {
types, err := GetComponentTypesWithParam(goo.GetType(testComponent2{}), []goo.Type{goo.GetType("")})
assert.Nil(t, err)
assert.Equal(t, 1, len(types))
types, err = GetComponentTypesWithParam(goo.GetType(testComponent2{}), []goo.Type{goo.GetType("")})
assert.Nil(t, err)
assert.Equal(t, 1, len(types))
}