Skip to content
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
23 changes: 2 additions & 21 deletions src/main/java/io/github/ktestify/config/FrameworkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
package io.github.ktestify.config;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigValueType;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import lombok.Getter;

Expand Down Expand Up @@ -55,7 +53,7 @@ public final class FrameworkConfig {

// Reporting
private final boolean enableReporting;
private final List<String> reportFormats;
private final String reportFormat;
private final String reportOutputDirectory;

FrameworkConfig(Config config) {
Expand Down Expand Up @@ -83,27 +81,10 @@ public final class FrameworkConfig {
// Reporting
Config reportConfig = config.getConfig("reporting");
this.enableReporting = reportConfig.getBoolean("enabled");
this.reportFormats = readReportFormats(reportConfig);
this.reportFormat = reportConfig.getString("format");
this.reportOutputDirectory = reportConfig.getString("output");
}

/**
* Reads the configured report formats.
*
* <p>{@code ktestify.framework.reporting.format} accepts either a single string ({@code format = "html"}) or an
* array of strings ({@code format = ["html", "json"]}). A single string is wrapped into a one-element list so
* existing configurations keep working.
*
* @param reportConfig the reporting config section
* @return the configured report formats, never null
*/
private static List<String> readReportFormats(Config reportConfig) {
if (reportConfig.getValue("format").valueType() == ConfigValueType.STRING) {
return List.of(reportConfig.getString("format"));
}
return List.copyOf(reportConfig.getStringList("format"));
}

private Optional<String> getOptionalString(Config config, String path) {
if (config.hasPath(path) && !config.getIsNull(path)) {
String value = config.getString(path);
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/application.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ ktestify {
# Reporting settings
reporting {
enabled = true
# One or more report formats: html, json, pretty
format = ["html"]
format = "html"
output = "target/test-output"
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ ktestify {
# Reporting settings
reporting {
enabled = true
# Report formats: html, json, pretty. Single value or array, e.g. ["html", "json"]
format = ["html"]
# Format: html, json, cucumber
format = "html"
# Directory for test output/reports
output = "src/target/reports/report.html"
output = ${?KTESTIFY_OUTPUT_DIR}
Expand Down
37 changes: 10 additions & 27 deletions src/test/java/io/github/ktestify/config/FrameworkConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.List;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

/**
* Comprehensive unit tests for FrameworkConfig. Tests all getters, timeout conversions, path resolution, and edge
Expand Down Expand Up @@ -339,9 +342,9 @@ void shouldGetEnableReporting() {
}

@Test
@DisplayName("Should get default report formats")
void shouldGetDefaultReportFormats() {
assertEquals(List.of("html"), frameworkConfig.getReportFormats());
@DisplayName("Should get report format")
void shouldGetReportFormat() {
assertEquals("html", frameworkConfig.getReportFormat());
}

@Test
Expand All @@ -357,36 +360,16 @@ void shouldHandleDisabledReporting() {
@Test
@DisplayName("Should handle different report formats")
void shouldHandleDifferentReportFormats() {
String[] formats = {"html", "json", "pretty"};
String[] formats = {"html", "json", "cucumber"};

for (String format : formats) {
KtestifyConfig config = ConfigBuilder.create()
.set("ktestify.framework.reporting.format", format)
.build();

assertEquals(List.of(format), config.getFramework().getReportFormats());
assertEquals(format, config.getFramework().getReportFormat());
}
}

@Test
@DisplayName("Should accept an array of report formats")
void shouldAcceptArrayOfReportFormats() {
KtestifyConfig config = ConfigBuilder.create()
.set("ktestify.framework.reporting.format", List.of("html", "json"))
.build();

assertEquals(List.of("html", "json"), config.getFramework().getReportFormats());
}

@Test
@DisplayName("Should handle an empty array of report formats")
void shouldHandleEmptyArrayOfReportFormats() {
KtestifyConfig config = ConfigBuilder.create()
.set("ktestify.framework.reporting.format", List.of())
.build();

assertTrue(config.getFramework().getReportFormats().isEmpty());
}
}

// ==========================================
Expand Down
Loading