-
-
Notifications
You must be signed in to change notification settings - Fork 47
CustomMockUnits
Andrei Ciobanu edited this page Mar 11, 2017
·
5 revisions
MockUnit<T>
is a Functional Interface that contains only one abstract method: Supplier<T> supplier();
.
Example: Creating a custom MockUnitString that returns random strings with the following format: [letter][digit][letter]
. Examples: "a2b", "w9z", "f8k", etc.
Supplier<String> supp = () -> {
StringBuilder buff = new StringBuilder();
buff.append(mock.chars().digits().val())
.append(mock.chars().lowerLetters().val())
.append(mock.chars().digits().val());
return buff.toString();
};
MockUnitString mockUnit = () -> supp;
// The custom created mockUnit can now be used
// as any other MockUnitString
String cStr = mockUnit.val();
List<String> lStr = mockUnit.list(10).val();
//etc.
Using the library:
Real World Examples: