diff --git a/src/main/java/org/kiwiproject/test/junit/jupiter/ResetLogbackLoggingExtension.java b/src/main/java/org/kiwiproject/test/junit/jupiter/ResetLogbackLoggingExtension.java index e6268bb..6339328 100644 --- a/src/main/java/org/kiwiproject/test/junit/jupiter/ResetLogbackLoggingExtension.java +++ b/src/main/java/org/kiwiproject/test/junit/jupiter/ResetLogbackLoggingExtension.java @@ -4,6 +4,7 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.extension.AfterAllCallback; @@ -56,10 +57,12 @@ @NoArgsConstructor @AllArgsConstructor(access = AccessLevel.PACKAGE) @Slf4j +@SuppressWarnings("LombokGetterMayBeUsed") public class ResetLogbackLoggingExtension implements AfterAllCallback { + @Getter @Builder.Default - private String logbackConfigFilePath = ClassicConstants.TEST_AUTOCONFIG_FILE; + private final String logbackConfigFilePath = ClassicConstants.TEST_AUTOCONFIG_FILE; @Override public void afterAll(ExtensionContext context) { diff --git a/src/test/java/org/kiwiproject/test/junit/jupiter/ResetLogbackLoggingExtensionTest.java b/src/test/java/org/kiwiproject/test/junit/jupiter/ResetLogbackLoggingExtensionTest.java new file mode 100644 index 0000000..9c145b0 --- /dev/null +++ b/src/test/java/org/kiwiproject/test/junit/jupiter/ResetLogbackLoggingExtensionTest.java @@ -0,0 +1,36 @@ +package org.kiwiproject.test.junit.jupiter; + +import static org.assertj.core.api.Assertions.assertThat; + +import ch.qos.logback.classic.ClassicConstants; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("ResetLogbackLoggingExtension") +class ResetLogbackLoggingExtensionTest { + + @Test + void shouldConstructWithLogbackTestFileAsDefaultConfigLocation() { + var extension = new ResetLogbackLoggingExtension(); + assertThat(extension.getLogbackConfigFilePath()) + .isEqualTo(ClassicConstants.TEST_AUTOCONFIG_FILE); + } + + @Test + void shouldBuildWithLogbackTestFileAsDefaultConfigLocation() { + var extension = ResetLogbackLoggingExtension.builder().build(); + assertThat(extension.getLogbackConfigFilePath()) + .isEqualTo(ClassicConstants.TEST_AUTOCONFIG_FILE); + } + + @Test + void shouldAllowCustomConfigLocation() { + var customLocation = "acme-test-logback.xml"; + + var extension = ResetLogbackLoggingExtension.builder() + .logbackConfigFilePath(customLocation) + .build(); + + assertThat(extension.getLogbackConfigFilePath()).isEqualTo(customLocation); + } +}