11/*
2- * Copyright 2012-2019 the original author or authors.
2+ * Copyright 2012-2020 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ void cleanUp() {
5151 @ Test
5252 void loadClass () {
5353 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , MyComponent .class );
54- assertThat (loader . load ()).isEqualTo (1 );
54+ assertThat (load (loader )).isEqualTo (1 );
5555 assertThat (this .registry .containsBean ("myComponent" )).isTrue ();
5656 }
5757
@@ -61,21 +61,21 @@ void anonymousClassNotLoaded() {
6161
6262 };
6363 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , myComponent .getClass ());
64- assertThat (loader . load ()).isEqualTo (0 );
64+ assertThat (load (loader )).isEqualTo (0 );
6565 }
6666
6767 @ Test
6868 void loadJsr330Class () {
6969 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , MyNamedComponent .class );
70- assertThat (loader . load ()).isEqualTo (1 );
70+ assertThat (load (loader )).isEqualTo (1 );
7171 assertThat (this .registry .containsBean ("myNamedComponent" )).isTrue ();
7272 }
7373
7474 @ Test
7575 void loadXmlResource () {
7676 ClassPathResource resource = new ClassPathResource ("sample-beans.xml" , getClass ());
7777 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , resource );
78- assertThat (loader . load ()).isEqualTo (1 );
78+ assertThat (load (loader )).isEqualTo (1 );
7979 assertThat (this .registry .containsBean ("myXmlComponent" )).isTrue ();
8080
8181 }
@@ -84,7 +84,7 @@ void loadXmlResource() {
8484 void loadGroovyResource () {
8585 ClassPathResource resource = new ClassPathResource ("sample-beans.groovy" , getClass ());
8686 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , resource );
87- assertThat (loader . load ()).isEqualTo (1 );
87+ assertThat (load (loader )).isEqualTo (1 );
8888 assertThat (this .registry .containsBean ("myGroovyComponent" )).isTrue ();
8989
9090 }
@@ -93,46 +93,46 @@ void loadGroovyResource() {
9393 void loadGroovyResourceWithNamespace () {
9494 ClassPathResource resource = new ClassPathResource ("sample-namespace.groovy" , getClass ());
9595 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , resource );
96- assertThat (loader . load ()).isEqualTo (1 );
96+ assertThat (load (loader )).isEqualTo (1 );
9797 assertThat (this .registry .containsBean ("myGroovyComponent" )).isTrue ();
9898
9999 }
100100
101101 @ Test
102102 void loadPackage () {
103103 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , MyComponent .class .getPackage ());
104- assertThat (loader . load ()).isEqualTo (2 );
104+ assertThat (load (loader )).isEqualTo (2 );
105105 assertThat (this .registry .containsBean ("myComponent" )).isTrue ();
106106 assertThat (this .registry .containsBean ("myNamedComponent" )).isTrue ();
107107 }
108108
109109 @ Test
110110 void loadClassName () {
111111 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , MyComponent .class .getName ());
112- assertThat (loader . load ()).isEqualTo (1 );
112+ assertThat (load (loader )).isEqualTo (1 );
113113 assertThat (this .registry .containsBean ("myComponent" )).isTrue ();
114114 }
115115
116116 @ Test
117117 void loadResourceName () {
118118 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry ,
119119 "classpath:org/springframework/boot/sample-beans.xml" );
120- assertThat (loader . load ()).isEqualTo (1 );
120+ assertThat (load (loader )).isEqualTo (1 );
121121 assertThat (this .registry .containsBean ("myXmlComponent" )).isTrue ();
122122 }
123123
124124 @ Test
125125 void loadGroovyName () {
126126 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry ,
127127 "classpath:org/springframework/boot/sample-beans.groovy" );
128- assertThat (loader . load ()).isEqualTo (1 );
128+ assertThat (load (loader )).isEqualTo (1 );
129129 assertThat (this .registry .containsBean ("myGroovyComponent" )).isTrue ();
130130 }
131131
132132 @ Test
133133 void loadPackageName () {
134134 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , MyComponent .class .getPackage ().getName ());
135- assertThat (loader . load ()).isEqualTo (2 );
135+ assertThat (load (loader )).isEqualTo (2 );
136136 assertThat (this .registry .containsBean ("myComponent" )).isTrue ();
137137 assertThat (this .registry .containsBean ("myNamedComponent" )).isTrue ();
138138 }
@@ -142,7 +142,7 @@ void loadPackageNameWithoutDot() {
142142 // See gh-6126
143143 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry ,
144144 MyComponentInPackageWithoutDot .class .getPackage ().getName ());
145- int loaded = loader . load ();
145+ int loaded = load (loader );
146146 assertThat (loaded ).isEqualTo (1 );
147147 assertThat (this .registry .containsBean ("myComponentInPackageWithoutDot" )).isTrue ();
148148 }
@@ -151,9 +151,15 @@ void loadPackageNameWithoutDot() {
151151 void loadPackageAndClassDoesNotDoubleAdd () {
152152 BeanDefinitionLoader loader = new BeanDefinitionLoader (this .registry , MyComponent .class .getPackage (),
153153 MyComponent .class );
154- assertThat (loader . load ()).isEqualTo (2 );
154+ assertThat (load (loader )).isEqualTo (2 );
155155 assertThat (this .registry .containsBean ("myComponent" )).isTrue ();
156156 assertThat (this .registry .containsBean ("myNamedComponent" )).isTrue ();
157157 }
158158
159+ private int load (BeanDefinitionLoader loader ) {
160+ int beans = this .registry .getBeanDefinitionCount ();
161+ loader .load ();
162+ return this .registry .getBeanDefinitionCount () - beans ;
163+ }
164+
159165}
0 commit comments