Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Added default value #79

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
import org.springframework.boot.context.properties.bind.DefaultValue;

/**
* Represents properties for managing pg-index-health-test-starter configuration.
Expand All @@ -27,7 +28,7 @@ public class DatabaseStructureHealthProperties {
*/
private final boolean enabled;

public DatabaseStructureHealthProperties(final boolean enabled) {
public DatabaseStructureHealthProperties(@DefaultValue("true") final boolean enabled) {
this.enabled = enabled;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@

class DatabaseStructureHealthAutoConfigurationTest extends AutoConfigurationTestBase {

@Test
void propertiesDefaultValueShouldBeUsed() {
assertWithTestConfig()
.run(context -> assertThat(context.getBean(DatabaseStructureHealthProperties.class))
.isInstanceOf(DatabaseStructureHealthProperties.class)
.satisfies(p -> assertThat(p.isEnabled()).isTrue()));
}

@Test
void withoutDataSource() {
assertWithTestConfig()
Expand Down Expand Up @@ -82,10 +90,14 @@ void shouldNotCreateAutoConfigurationWithDisabledProperty() {
assertWithTestConfig()
.withPropertyValues("pg.index.health.test.enabled=false")
.withInitializer(AutoConfigurationTestBase::initialize)
.run(context -> assertThat(context.getBeanDefinitionNames())
.isNotEmpty()
.filteredOn(beanNamesFilter)
.isEmpty());
.run(context -> {
assertThat(context.getBeansOfType(DatabaseStructureHealthProperties.class))
.isEmpty();
assertThat(context.getBeanDefinitionNames())
.isNotEmpty()
.filteredOn(beanNamesFilter)
.isEmpty();
});
}

@Test
Expand Down