abstract class YamlFakeDataProvider<T : FakeDataProvider> : AbstractFakeDataProvider<T>

Abstract class for all concrete FakeDataProvider's that use yml files as data source.

Fields

Name Description
protected abstract yamlCategory: YamlCategory

Category for this fake yaml data provider class.

This is the key entry after the faker key in .yml locale file.

For example address.yml file has the following structure:


en:
  faker:
    address:

then the yamlCategory would be YamlCategory.ADDRESS

NB! If the secondaryCategory is NOT set,the dictionary filename should match the yamlCategory name,i.e. the file name should be address.yml for the YamlCategory.ADDRESS.

protected open secondaryCategory: Category?

Secondary category for this fake yaml data provider class.

This is the key entry after the yamlCategory key in .yml locale file.

For example dog.yml file has the following structure:


en:
  faker:
    creature:
      dog:

then the yamlCategory would be YamlCategory.CREATURE, and the secondary Category.name would be "dog"

TIP: Use Category.ofName helper function when needed.

NB! If the secondaryCategory is set,the dictionary filename should match the Category.name of this secondaryCategory,i.e. the file name should be dog.yml for the [Category.ofName] dog.

protected category: YamlCategory

Category of this fake data provider class.

Constructors

<init>

constructor(fakerService: FakerService)

Abstract class for all concrete FakeDataProvider's that use yml files as data source.

Parameters

Name Description
fakerService: FakerService

Methods

resolve

protected fun resolve(key: String): String

Returns resolved (unique) value for the parameter with the specified key.

Will return a unique value if the call to the function is prefixed with unique property. Example:


faker.address.unique.city() => will return a unique value for the `city` parameter

Parameters

Name Description
key: String

ReturnValue

Name Description
String

resolve

protected fun resolve(keys: AltKey<String, String>): String

Returns resolved (unique) value for the parameter with the specified pair of keys, where first is the "altKey" and second is the "primaryKey".

This function can be used to resolve locale-specific keys that are not present in the default 'en' dictionaries.

An example usage (taken from Address.countryCode) looks something like this:


fun countryCode() = resolve("default_country_code" or "country_code")

Here, the "default_country_code" is the key that is only present in the localized dictionaries, which may or may not be present in the default 'en' dictionary, and "country_code" is the default key for this function which is defined in en/address.yml dict file.

Will attempt to return a unique value if the call to the function is prefixed with unique property. Example:


faker.address.unique.countryCode() => will return a unique value for the `country_code` parameter.

Parameters

Name Description
keys: AltKey<String, String>

ReturnValue

Name Description
String

resolve

protected fun resolve(primaryKey: Category, secondaryKey: String): String

Returns resolved (unique) value for the parameter with the specified primaryKey and secondaryKey.

TIP: Can be useful for providers that override this secondaryCategory to use a compile-safe object instead of a string for the primaryKey.

Example:


class Minecraft internal constructor(fakerService: FakerService) : YamlFakeDataProvider(fakerService) {
  override val yamlCategory = YamlCategory.GAMES
  override val secondaryCategory: Category = Category.ofName("MINECRAFT")
  override val localUniqueDataProvider = LocalUniqueDataProvider()
  override val unique by UniqueProviderDelegate(localUniqueDataProvider, fakerService)

  fun achievement() = resolve("minecraft", "achievement")
  fun biome() = resolve(secondaryCategory, "biome")
}

Will return a unique value if the call to the function is prefixed with unique property. Example:


faker.address.unique.countryByCode(countryCode) => will return a unique value for the `city` parameter

Parameters

Name Description
primaryKey: Category
secondaryKey: String

ReturnValue

Name Description
String

resolve

protected fun resolve(primaryKey: String, secondaryKey: String): String

Returns resolved (unique) value for the parameter with the specified primaryKey and secondaryKey.

Will return a unique value if the call to the function is prefixed with unique property. Example:


faker.address.unique.countryByCode(countryCode) => will return a unique value for the `city` parameter

Parameters

Name Description
primaryKey: String
secondaryKey: String

ReturnValue

Name Description
String

resolve

protected fun resolve(primaryKey: Category, secondaryKey: String, thirdKey: String): String

Returns resolved (unique) value for the parameter with the specified primaryKey, secondaryKey and thirdKey

Will return a unique value if the call to the function is prefixed with unique property. Example:


faker.educator.tertiaryDegree(type) => will return a unique value for the `tertiaryDegree` parameter

Parameters

Name Description
primaryKey: Category
secondaryKey: String
thirdKey: String

ReturnValue

Name Description
String

resolve

protected fun resolve(primaryKey: String, secondaryKey: String, thirdKey: String): String

Returns resolved (unique) value for the parameter with the specified primaryKey, secondaryKey and thirdKey

Will return a unique value if the call to the function is prefixed with unique property. Example:


faker.educator.tertiaryDegree(type) => will return a unique value for the `tertiaryDegree` parameter

Parameters

Name Description
primaryKey: String
secondaryKey: String
thirdKey: String

ReturnValue

Name Description
String