@@ -23,18 +23,12 @@ import (
2323 "reflect"
2424 "testing"
2525
26- "github.com/go-spring-projects/go-spring/gs/arg"
2726 pkg1 "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar"
2827 pkg2 "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo"
2928 "github.com/go-spring-projects/go-spring/internal/utils"
3029 "github.com/go-spring-projects/go-spring/internal/utils/assert"
3130)
3231
33- // newBean 该方法是为了平衡调用栈的深度,一般情况下 gs.NewBean 不应该被直接使用。
34- func newBean (objOrCtor interface {}, ctorArgs ... arg.Arg ) * BeanDefinition {
35- return NewBean (objOrCtor , ctorArgs ... )
36- }
37-
3832//func TestParseSingletonTag(t *testing.T) {
3933//
4034// data := map[string]SingletonTag{
@@ -112,18 +106,18 @@ func TestBeanDefinition_Match(t *testing.T) {
112106 beanName string
113107 expect bool
114108 }{
115- {newBean (new (pkg2.SamePkg )), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" , "SamePkg" , true },
116- {newBean (new (pkg2.SamePkg )), "" , "SamePkg" , true },
117- {newBean (new (pkg2.SamePkg )), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" , "" , true },
118- {newBean (new (pkg2.SamePkg )).Name ("pkg2" ), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" , "pkg2" , true },
119- {newBean (new (pkg2.SamePkg )).Name ("pkg2" ), "" , "pkg2" , true },
120- {newBean (new (pkg2.SamePkg )).Name ("pkg2" ), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" , "pkg2" , true },
121- {newBean (new (pkg1.SamePkg )), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar/pkg.SamePkg" , "SamePkg" , true },
122- {newBean (new (pkg1.SamePkg )), "" , "SamePkg" , true },
123- {newBean (new (pkg1.SamePkg )), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar/pkg.SamePkg" , "" , true },
124- {newBean (new (pkg1.SamePkg )).Name ("pkg1" ), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar/pkg.SamePkg" , "pkg1" , true },
125- {newBean (new (pkg1.SamePkg )).Name ("pkg1" ), "" , "pkg1" , true },
126- {newBean (new (pkg1.SamePkg )).Name ("pkg1" ), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar/pkg.SamePkg" , "pkg1" , true },
109+ {NewBean (new (pkg2.SamePkg )), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" , "SamePkg" , true },
110+ {NewBean (new (pkg2.SamePkg )), "" , "SamePkg" , true },
111+ {NewBean (new (pkg2.SamePkg )), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" , "" , true },
112+ {NewBean (new (pkg2.SamePkg )).Name ("pkg2" ), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" , "pkg2" , true },
113+ {NewBean (new (pkg2.SamePkg )).Name ("pkg2" ), "" , "pkg2" , true },
114+ {NewBean (new (pkg2.SamePkg )).Name ("pkg2" ), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" , "pkg2" , true },
115+ {NewBean (new (pkg1.SamePkg )), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar/pkg.SamePkg" , "SamePkg" , true },
116+ {NewBean (new (pkg1.SamePkg )), "" , "SamePkg" , true },
117+ {NewBean (new (pkg1.SamePkg )), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar/pkg.SamePkg" , "" , true },
118+ {NewBean (new (pkg1.SamePkg )).Name ("pkg1" ), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar/pkg.SamePkg" , "pkg1" , true },
119+ {NewBean (new (pkg1.SamePkg )).Name ("pkg1" ), "" , "pkg1" , true },
120+ {NewBean (new (pkg1.SamePkg )).Name ("pkg1" ), "github.com/go-spring-projects/go-spring/gs/testdata/pkg/bar/pkg.SamePkg" , "pkg1" , true },
127121 }
128122
129123 for i , s := range data {
@@ -161,12 +155,12 @@ func TestObjectBean(t *testing.T) {
161155 t .Run ("bean must be ref type" , func (t * testing.T ) {
162156
163157 data := []func (){
164- func () { newBean ([... ]int {0 }) },
165- func () { newBean (false ) },
166- func () { newBean (3 ) },
167- func () { newBean ("3" ) },
168- func () { newBean (BeanZero {}) },
169- func () { newBean (pkg2.SamePkg {}) },
158+ func () { NewBean ([... ]int {0 }) },
159+ func () { NewBean (false ) },
160+ func () { NewBean (3 ) },
161+ func () { NewBean ("3" ) },
162+ func () { NewBean (BeanZero {}) },
163+ func () { NewBean (pkg2.SamePkg {}) },
170164 }
171165
172166 for _ , fn := range data {
@@ -175,9 +169,9 @@ func TestObjectBean(t *testing.T) {
175169 })
176170
177171 t .Run ("valid bean" , func (t * testing.T ) {
178- newBean (make (chan int ))
179- newBean (reflect .ValueOf (func () {}))
180- newBean (& BeanZero {})
172+ NewBean (make (chan int ))
173+ NewBean (reflect .ValueOf (func () {}))
174+ NewBean (& BeanZero {})
181175 })
182176
183177 t .Run ("check name && typename" , func (t * testing.T ) {
@@ -186,21 +180,21 @@ func TestObjectBean(t *testing.T) {
186180 name string
187181 typeName string
188182 }{
189- newBean (io .Writer (os .Stdout )): {
183+ NewBean (io .Writer (os .Stdout )): {
190184 "File" , "os/os.File" ,
191185 },
192186
193- newBean (newHistoryTeacher ("" )): {
187+ NewBean (newHistoryTeacher ("" )): {
194188 "historyTeacher" ,
195189 "github.com/go-spring-projects/go-spring/gs/gs.historyTeacher" ,
196190 },
197191
198- newBean (new (pkg2.SamePkg )): {
192+ NewBean (new (pkg2.SamePkg )): {
199193 "SamePkg" ,
200194 "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" ,
201195 },
202196
203- newBean (new (pkg2.SamePkg )).Name ("pkg2" ): {
197+ NewBean (new (pkg2.SamePkg )).Name ("pkg2" ): {
204198 "pkg2" ,
205199 "github.com/go-spring-projects/go-spring/gs/testdata/pkg/foo/pkg.SamePkg" ,
206200 },
@@ -215,30 +209,30 @@ func TestObjectBean(t *testing.T) {
215209
216210func TestConstructorBean (t * testing.T ) {
217211
218- bd := newBean (NewStudent )
212+ bd := NewBean (NewStudent )
219213 assert .Equal (t , bd .Type ().String (), "*gs.Student" )
220214
221- bd = newBean (NewPtrStudent )
215+ bd = NewBean (NewPtrStudent )
222216 assert .Equal (t , bd .Type ().String (), "*gs.Student" )
223217
224218 //mapFn := func() map[int]string { return make(map[int]string) }
225- //bd = newBean (mapFn)
219+ //bd = NewBean (mapFn)
226220 //assert.Equal(t, bd.Type().String(), "*map[int]string")
227221
228222 //sliceFn := func() []int { return make([]int, 1) }
229- //bd = newBean (sliceFn)
223+ //bd = NewBean (sliceFn)
230224 //assert.Equal(t, bd.Type().String(), "*[]int")
231225
232226 funcFn := func () func (int ) { return nil }
233- bd = newBean (funcFn )
227+ bd = NewBean (funcFn )
234228 assert .Equal (t , bd .Type ().String (), "func(int)" )
235229
236230 interfaceFn := func (name string ) Teacher { return newHistoryTeacher (name ) }
237- bd = newBean (interfaceFn )
231+ bd = NewBean (interfaceFn )
238232 assert .Equal (t , bd .Type ().String (), "gs.Teacher" )
239233
240234 assert .Panic (t , func () {
241- _ = newBean (func () (* int , * int ) { return nil , nil })
235+ _ = NewBean (func () (* int , * int ) { return nil , nil })
242236 }, "constructor should be func\\ (...\\ )bean or func\\ (...\\ )\\ (bean, error\\ )" )
243237}
244238
0 commit comments