Back to Repositories

Testing Property Configuration Management in Stirling-PDF

This test suite validates the PropertyConfigs utility class functionality in Stirling-PDF, focusing on property value retrieval methods. The tests verify both boolean and string property handling with single and multiple key scenarios.

Test Coverage Overview

The test suite provides comprehensive coverage of PropertyConfigs utility methods.

Key areas tested include:
  • Boolean property retrieval with multiple keys
  • String property retrieval with multiple keys
  • Single key boolean property handling
  • Single key string property handling
Edge cases cover default value fallbacks and system property interactions.

Implementation Analysis

The testing approach utilizes JUnit Jupiter for systematic verification of property configuration handling.

Key implementation patterns include:
  • System property manipulation for test scenarios
  • Multiple key fallback testing
  • Default value verification
  • Assertion-based result validation

Technical Details

Testing infrastructure includes:
  • JUnit Jupiter test framework
  • Java System Properties integration
  • Arrays utility for key list creation
  • Assert methods for result verification

Best Practices Demonstrated

The test suite exemplifies strong testing practices through clear test case organization and thorough validation.

Notable practices include:
  • Descriptive test method naming
  • Isolated test scenarios
  • Comprehensive assertion coverage
  • Clean setup and teardown patterns

stirling-tools/stirling-pdf

src/test/java/stirling/software/SPDF/utils/PropertyConfigsTest.java

            
package stirling.software.SPDF.utils;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class PropertyConfigsTest {

    @Test
    public void testGetBooleanValue_WithKeys() {
        // Define keys and default value
        List<String> keys = Arrays.asList("test.key1", "test.key2", "test.key3");
        boolean defaultValue = false;

        // Set property for one of the keys
        System.setProperty("test.key2", "true");

        // Call the method under test
        boolean result = PropertyConfigs.getBooleanValue(keys, defaultValue);

        // Verify the result
        assertEquals(true, result);
    }

    @Test
    public void testGetStringValue_WithKeys() {
        // Define keys and default value
        List<String> keys = Arrays.asList("test.key1", "test.key2", "test.key3");
        String defaultValue = "default";

        // Set property for one of the keys
        System.setProperty("test.key2", "value");

        // Call the method under test
        String result = PropertyConfigs.getStringValue(keys, defaultValue);

        // Verify the result
        assertEquals("value", result);
    }

    @Test
    public void testGetBooleanValue_WithKey() {
        // Define key and default value
        String key = "test.key";
        boolean defaultValue = true;

        // Call the method under test
        boolean result = PropertyConfigs.getBooleanValue(key, defaultValue);

        // Verify the result
        assertEquals(true, result);
    }

    @Test
    public void testGetStringValue_WithKey() {
        // Define key and default value
        String key = "test.key";
        String defaultValue = "default";

        // Call the method under test
        String result = PropertyConfigs.getStringValue(key, defaultValue);

        // Verify the result
        assertEquals("default", result);
    }
}