All Implemented Interfaces:

public final class TestData extends Object implements ComponentConfigurer<DataSource>
A mechanism for providing dynamically updatable feature flag state in a simplified form to an SDK client in test scenarios.

This mechanism does not use any external resources. It provides only the data that the application has put into it using the update(FlagBuilder) method.

The example code below uses a simple boolean flag, but more complex configurations are possible using the methods of the TestData.FlagBuilder that is returned by flag(String).

     TestData td = TestData.dataSource();

     LDConfig config = new LDConfig.Builder()
     LDClient client = new LDClient(sdkKey, config, initialContext, startWaitSeconds);

     // flags can be updated at any time:
         .variationForUser("some-user-key", false));
  • Method Details

    • dataSource

      public static TestData dataSource()
      Creates a new instance of the test data source.

      See TestData for details.

      a new configurable test data source
    • flag

      public TestData.FlagBuilder flag(String key)
      Creates or copies a TestData.FlagBuilder for building a test flag configuration.

      If this flag key has already been defined in this TestData instance, then the builder starts with the same configuration that was last provided for this flag.

      Otherwise, it starts with a new default configuration in which the flag has true and false variations, and is true by default for all contexts. You can change any of those properties, and provide more complex behavior, using the TestData.FlagBuilder\ methods.

      Once you have set the desired configuration, pass the builder to update(FlagBuilder).

      key - the flag key
      a flag configuration builder
      See Also:
    • update

      public TestData update(TestData.FlagBuilder flagBuilder)
      Updates the test data with the specified flag configuration.

      This has the same effect as if a flag were added or modified on the LaunchDarkly dashboard. It immediately propagates the flag change to any LDClient instance(s) that you have already configured to use this TestData. If no LDClient has been started yet, it simply adds this flag to the test data which will be provided to any LDClient that you subsequently configure.

      Any subsequent changes to this TestData.FlagBuilder instance do not affect the test data, unless you call update(FlagBuilder) again.

      flagBuilder - a flag configuration builder
      the same TestData instance
      See Also:
    • build

      public DataSource build(ClientContext clientContext)
      Description copied from interface: ComponentConfigurer
      Called internally by the SDK to create an implementation instance. Applications should not need to call this method.
      Specified by:
      build in interface ComponentConfigurer<DataSource>
      clientContext - provides configuration properties and other components from the current SDK client instance
      a instance of the component type