Class Unique


public class Unique extends AbstractProvider<BaseProviders>
This class contains methods that ensure uniqueness across separate invocations.

This can be helpful for unit tests and automated tests where certain values need to be different.

Since:
1.6.0
  • Constructor Details

  • Method Details

    • fetchFromYaml

      public String fetchFromYaml(String key)
      Returns a random value from the YAML files that is guaranteed to be unique for the given key and locale set on the current faker instance.

      Since unique values are tracked by both the key and the locale, manually changing the locale could cause this method to return the same value for a given key if there is not a separate locale for the given key.

      Parameters:
      key - the key of the values to fetch from the YAML files
      Returns:
      a unique random value based on key and the current locale
      Throws:
      NoSuchElementException - if key does not correspond to a list of valid data types in the YAML files, or if all possible values found for key and current locale have been returned