public class FakeValuesService extends Object
Constructor and Description |
---|
FakeValuesService(Locale locale,
RandomService randomService)
Resolves YAML file using the most specific path first based on language and country code.
|
Modifier and Type | Method and Description |
---|---|
String |
bothify(String string)
Applies both a
numerify(String) and a letterify(String)
over the incoming string. |
String |
bothify(String string,
boolean isUpper)
Applies both a
numerify(String) and a letterify(String, boolean)
over the incoming string. |
String |
expression(String expression,
Faker faker)
resolves an expression using the current faker.
|
Object |
fetch(String key)
Fetch a random value from an array item specified by the key
|
Object |
fetchObject(String key)
Return the object selected by the key from yaml file.
|
String |
fetchString(String key)
Same as
fetch(String) except this casts the result into a String. |
String |
letterify(String letterString)
Returns a string with the '?' characters in the parameter replaced with random alphabetic
characters.
|
String |
letterify(String letterString,
boolean isUpper)
Returns a string with the '?' characters in the parameter replaced with random alphabetic
characters.
|
protected List<Locale> |
localeChain(Locale from)
Convert the specified locale into a chain of locales used for message resolution.
|
String |
numerify(String numberString)
Returns a string with the '#' characters in the parameter replaced with random digits between 0-9 inclusive.
|
String |
regexify(String regex)
Generates a String that matches the given regular expression.
|
String |
resolve(String key,
Object current,
Faker root)
Resolves a key to a method on an object.
|
protected String |
resolveExpression(String expression,
Object current,
Faker root)
processes a expression in the style #{X.y} using the current objects as the 'current' location
within the yml file (or the
Faker object hierarchy as it were). |
String |
safeFetch(String key,
String defaultIfNull)
Safely fetches a key.
|
public FakeValuesService(Locale locale, RandomService randomService)
Resolves YAML file using the most specific path first based on language and country code. 'en_US' would resolve in the following order:
Locale
instance. This is legacy behavior and not
condoned, but it will work.
locale
- randomService
- protected List<Locale> localeChain(Locale from)
Locale.FRANCE
(fr_FR) -> [ fr_FR, anotherTest, en ]
Locale
instancespublic Object fetch(String key)
key
- public String fetchString(String key)
fetch(String)
except this casts the result into a String.key
- public String safeFetch(String key, String defaultIfNull)
If the value is null, it will return an empty string.
If it is a list, it will assume it is a list of strings and select a random value from it.
If the retrieved value is an slash encoded regular expression such as /[a-b]/
then
the regex will be converted to a regexify expression and returned (ex. #regexify '[a-b]'
)
Otherwise it will just return the value as a string.
key
- the key to fetch from the YML structure.defaultIfNull
- the value to return if the fetched value is nullpublic Object fetchObject(String key)
key
- key contains path to an object. Path segment is separated by
dot. E.g. name.first_namepublic String numerify(String numberString)
numberString
- public String bothify(String string)
numerify(String)
and a letterify(String)
over the incoming string.string
- public String bothify(String string, boolean isUpper)
numerify(String)
and a letterify(String, boolean)
over the incoming string.string
- isUpper
- public String regexify(String regex)
public String letterify(String letterString)
letterString
- public String letterify(String letterString, boolean isUpper)
letterString
- isUpper
- specifies whether or not letters should be upper casepublic String resolve(String key, Object current, Faker root)
#{hello} with result in a method call to current.hello();
#{Person.hello_someone} will result in a method call to person.helloSomeone();
public String expression(String expression, Faker faker)
expression
- faker
- protected String resolveExpression(String expression, Object current, Faker root)
processes a expression in the style #{X.y} using the current objects as the 'current' location
within the yml file (or the Faker
object hierarchy as it were).
#{Address.streetName} would get resolved to Faker.address()
's Address.streetName()
#{address.street} would get resolved to the YAML > locale: faker: address: street:
Combinations are supported as well: "#{x} #{y}"
Recursive templates are supported. if "#{x}" resolves to "#{Address.streetName}" then "#{x}" resolves to
Faker.address()
's Address.streetName()
.
Copyright © 2019. All rights reserved.