use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class IgnoreTopLevelConverterNotFoundBindHandlerTests method setup.
@BeforeEach
void setup() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example", "bar");
this.sources.add(source);
this.binder = new Binder(this.sources);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class PackagePrivateBeanBindingTests method bindToPackagePrivateClassShouldBindToInstance.
@Test
void bindToPackagePrivateClassShouldBindToInstance() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar", "999");
this.sources.add(source);
ExamplePackagePrivateBean bean = this.binder.bind(this.name, Bindable.of(ExamplePackagePrivateBean.class)).get();
assertThat(bean.getBar()).isEqualTo(999);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerThrowException.
@Test
void bindWhenUsingNoUnboundElementsHandlerThrowException() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example.foo", "bar");
source.put("example.baz", "bar");
this.sources.add(source);
this.binder = new Binder(this.sources);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("example", Bindable.of(Example.class), new NoUnboundElementsBindHandler())).satisfies((ex) -> assertThat(ex.getCause().getMessage()).contains("The elements [example.baz] were left unbound"));
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class NoUnboundElementsBindHandlerTests method bindWhenNotUsingNoUnboundElementsHandlerShouldBind.
@Test
void bindWhenNotUsingNoUnboundElementsHandlerShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example.foo", "bar");
source.put("example.baz", "bar");
this.sources.add(source);
this.binder = new Binder(this.sources);
Example bound = this.binder.bind(ConfigurationPropertyName.of("example"), Bindable.of(Example.class)).get();
assertThat(bound.getFoo()).isEqualTo("bar");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerShouldBind.
@Test
void bindWhenUsingNoUnboundElementsHandlerShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example.foo", "bar");
this.sources.add(source);
this.binder = new Binder(this.sources);
Example bound = this.binder.bind("example", Bindable.of(Example.class), new NoUnboundElementsBindHandler()).get();
assertThat(bound.getFoo()).isEqualTo("bar");
}
Aggregations