Skip to content

Commit

Permalink
Add test for ResetLogbackLoggingExtension
Browse files Browse the repository at this point in the history
* Make logbackConfigFilePath final in ResetLogbackLoggingExtension
* Add test that verifies default and custom config locations
  • Loading branch information
sleberknight committed Feb 9, 2024
1 parent c72d357 commit 347166b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 347166b

Please sign in to comment.