Skip to content

Commit dafd848

Browse files
fix unit tests (#18)
1 parent a1405d0 commit dafd848

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

src/main/java/com/freemanan/starter/httpexchange/HttpClientBeanRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void registerHttpClientBean(BeanDefinitionRegistry registry, String class
111111
ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(abd, className), registry, false);
112112
BeanDefinitionReaderUtils.registerBeanDefinition(scopedProxy, registry);
113113
} else {
114-
registry.registerBeanDefinition(className, abd);
114+
BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(abd, className), registry);
115115
}
116116
} catch (BeanDefinitionOverrideException ignore) {
117117
// clients are included in base packages

src/test/java/com/freemanan/starter/httpexchange/DynamicRefreshTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.springframework.boot.builder.SpringApplicationBuilder;
1212
import org.springframework.cloud.endpoint.event.RefreshEvent;
1313
import org.springframework.context.annotation.Configuration;
14-
import org.springframework.core.env.ConfigurableEnvironment;
1514
import org.springframework.web.bind.annotation.GetMapping;
1615
import org.springframework.web.bind.annotation.RestController;
1716
import org.springframework.web.service.annotation.GetExchange;
@@ -29,17 +28,17 @@ void testDynamicRefresh() {
2928
.properties("server.port=" + port)
3029
.properties("http-exchange.base-url=http://localhost:" + port)
3130
.run();
32-
ConfigurableEnvironment env = ctx.getEnvironment();
3331

3432
FooApi api = ctx.getBean(FooApi.class);
3533
assertThat(api.get()).isEqualTo("OK");
3634

37-
env.getSystemProperties().put("http-exchange.base-url", "http://localhost:" + port + "/v2");
35+
System.setProperty("http-exchange.base-url", "http://localhost:" + port + "/v2");
3836
ctx.publishEvent(new RefreshEvent(ctx, null, null));
3937

4038
// base-url changed
4139
assertThat(api.get()).isEqualTo("OK v2");
4240

41+
System.clearProperty("http-exchange.base-url");
4342
ctx.close();
4443
}
4544

src/test/java/com/freemanan/starter/httpexchange/ExtendShadedTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void userApiFirst_whenHaveControllerAndApiBeans() {
3737
.properties("server.port=" + port)
3838
.run();
3939
long count = ctx.getBeanProvider(FooApi.class).stream().count();
40-
assertThat(count).isEqualTo(2);
40+
assertThat(count).isEqualTo(3);
4141

4242
FooApi fooApi = ctx.getBean(FooApi.class);
4343
assertThat(fooApi).isNotInstanceOf(FooController.class);

src/test/java/com/freemanan/starter/httpexchange/ExtendTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void userApiFirst_whenHaveControllerAndApiBeans() {
3434
.profiles("ControllerApiTests")
3535
.properties("server.port=" + port)
3636
.run();
37-
assertThat(ctx.getBeanProvider(FooApi.class)).hasSize(2);
37+
assertThat(ctx.getBeanProvider(FooApi.class)).hasSize(3);
3838

3939
FooApi fooApi = ctx.getBean(FooApi.class);
4040
assertThat(fooApi).isNotInstanceOf(FooController.class);

0 commit comments

Comments
 (0)