org.springframework.boot.test.util

Class TestPropertyValues



  • public final class TestPropertyValues
    extends Object
    Test utilities for adding properties. Properties can be applied to a Spring Environment or to the system environment.
    Since:
    2.0.0
    Author:
    Madhura Bhave, Phillip Webb, Stephane Nicoll
    • Method Detail

      • applyTo

        public void applyTo(ConfigurableEnvironment environment)
        Add the properties from the underlying map to the environment. The default property source used is MapPropertySource.
        Parameters:
        environment - the environment that needs to be modified
      • applyToSystemProperties

        public <T> T applyToSystemProperties(Callable<T> call)
        Add the properties to the system properties for the duration of the call, restoring previous values when the call completes.
        Type Parameters:
        T - the result type
        Parameters:
        call - the call to make
        Returns:
        the result of the call
      • of

        public static TestPropertyValues of(String... pairs)
        Return a new TestPropertyValues with the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.
        Parameters:
        pairs - the name-value pairs for properties that need to be added to the environment
        Returns:
        the new instance
      • of

        public static TestPropertyValues of(Iterable<String> pairs)
        Return a new TestPropertyValues with the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.
        Parameters:
        pairs - the name-value pairs for properties that need to be added to the environment
        Returns:
        the new instance
      • of

        public static TestPropertyValues of(Stream<String> pairs)
        Return a new TestPropertyValues with the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.
        Parameters:
        pairs - the name-value pairs for properties that need to be added to the environment
        Returns:
        the new instance