### Display month with display() Source: https://www.mockneat.com/docs Example of displaying a month using specific text style and locale. ```java String month = months() .before(JULY) .display(TextStyle.FULL, Locale.CANADA) .val(); //Possible Ouput: May ``` -------------------------------- ### base64() Encoding Example Source: https://www.mockneat.com/docs Encodes a list of generated names into Base64 format. ```java // Generate a list of names List names = names() .first() .format(CAPITALIZED) .list(5) .val(); // Possible Output: [Carroll, Zane, Alfred, Brent, Loren] // Using seq() we iterate through the previous list and we encode the strings List base64names = seq(names) .mapToString() .base64() .list(5) .val(); // Possible Output: [Q2Fycm9sbA==, WmFuZQ==, QWxmcmVk, QnJlbnQ=, TG9yZW4=] ``` -------------------------------- ### intSeq() Source: https://www.mockneat.com/docs Generates a sequence of integers with configurable start, increment, max/min, and cycling behavior. ```APIDOC ## intSeq() ### Description Generates a sequence of integers. Supports configuration of start value, increment, maximum or minimum value, and cycling. ### Method intSeq() ### Parameters #### Optional Methods - **start(int)** - Optional - The starting value of the sequence. Default is 0. - **increment(int)** - Optional - The increment between each value. Default is 1. - **max(int)** - Optional - The maximum value before resetting (if cycle is true). - **min(int)** - Optional - The minimum value before resetting (if cycle is true). Default is Integer.MIN_VALUE. - **cycle(boolean)** - Optional - Whether to reset the sequence when reaching the max or min value. ### Returns - **IntSeq** - The sequence object, call get() to retrieve the next value. ### Examples ```java // Default sequence: 0, 1, 2, ... IntSeq seq = intSeq(); for(int i = 0; i < 20; i++) { System.out.print(seq.get() + " "); } // Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Custom sequence with cycling IntSeq seq2 = intSeq() .start(5) .increment(2) .max(20) .cycle(true); for(int i = 0; i < 50; i++) { System.out.print(seq2.get() + " "); } // Output: 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 ``` ``` -------------------------------- ### Get all dictionary data as a list with dicts().data() Source: https://www.mockneat.com/docs The data() method returns an immutable list of all entries for a given DictType. This example retrieves all country ISO codes. ```java List cIso2 = dicts().data(DictType.COUNTRY_ISO_CODE_2); ``` -------------------------------- ### Generate addresses with addresses() Source: https://www.mockneat.com/docs Generates user address components or full addresses. The output shows examples of line 1, line 2, and a full address. ```java addresses().line1().consume(System.out::println); addresses().line2().consume(System.out::println); addresses().consume(System.out::println); ``` ```text 7792 Poke Blvd Suite 305 16228 Scouters Rd Line 543 ``` -------------------------------- ### array() Generation Example Source: https://www.mockneat.com/docs Generates an array of 10 random days. ```java // ARRAY String[] someDays = days() .display() .array(10) .val(); // Possible Output: [Saturday, Monday, Monday, Sunday, Sunday, Tuesday, Thursday, Friday, Monday, Wednesday] ``` -------------------------------- ### Create an array of 100 random Doubles Source: https://www.mockneat.com/docs Example for creating an array of 100 random Doubles, with values between [1000.0, 2000.0). ```java Double[] array = doubles() .range(1000.0, 2000.0) .array(100) .val(); ``` -------------------------------- ### append() String Suffix Example Source: https://www.mockneat.com/docs Appends a specific suffix to generated city names. ```java // APPEND String[] cityAppend = cities() .capitals() .append("-001") // To each generated String we append "-001" .array(10) .val(); // Possible Output: [Bishkek-001, Ulaanbaatar-001, Kigali-001, Bratislava-001, Sarajevo-001, Kabul-001, Lusaka-001, Port Vila-001, Tegucigalpa-001, Astana-001] ``` -------------------------------- ### Generate Configurable Integer Sequence with intSeq() Source: https://www.mockneat.com/docs Generates a sequence starting at 5, incrementing by 2, with a maximum value of 20 and cycling enabled. ```java IntSeq seq2 = intSeq() .start(5) .increment(2) .max(20) .cycle(true); for(int i = 0; i < 50; i++) { System.out.print(seq2.get() + " "); } // Output: 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 ``` -------------------------------- ### Generate Integer Sequence with intSeq() Source: https://www.mockneat.com/docs Generates a sequence of integers starting at 0 and incrementing by 1. ```java IntSeq seq = intSeq(); for(int i = 0; i < 20; i++) { System.out.print(seq.get() + " "); } // Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ``` -------------------------------- ### accumulate() HTML Generation Example Source: https://www.mockneat.com/docs Generates an HTML unordered list by mapping characters to list items and accumulating them with newline separators. ```java StringBuilder buff = new StringBuilder(); buff.append("
    \n") .append( chars() .upperLetters() .mapToString((c) -> String.format("\t
  • %s
  • ", c.toString())) .accumulate(5, "\n") .get() ) .append("\n
"); System.out.println(buff.toString()); //Output: /**
  • Q
  • F
  • F
  • H
  • S
into a MockUnitDouble using a Function. The example shows converting a MockUnit to a double range based on the boolean value. ```APIDOC ## mapToDouble() ### Description Transforms a MockUnit into a more specific MockUnitDouble using a Function. ### Method mapToDouble ### Parameters - **function** (Function) - Required - The function that maps a value of type T to a Double. ### Example ```java MockUnitDouble md = bools() .mapToDouble((bool) -> { if (bool) return doubles().range(1.0, 2.0).val(); return doubles().range(2.0, 3.0).val(); }); Double d = md.val(); ``` ### Returns MockUnitDouble - A MockUnit that generates Double values. ``` -------------------------------- ### mapToString() Source: https://www.mockneat.com/docs Translates a MockUnit into a MockUnitString. Without parameters, it calls toString() on the generated object; with a Function, it applies additional processing. Examples show generating integer values as strings and mapping integers to 'odd' or 'even'. ```APIDOC ## mapToString() ### Description Translates a MockUnit into a MockUnitString. If no function is provided, toString() is called on the generated object. Otherwise, a Function is applied. ### Method mapToString() or mapToString(Function) ### Parameters - **function** (Function) - Optional - The function that converts a generated value of type T to a String. ### Returns MockUnitString - A mock unit that generates String values. ### Examples ```java MockUnitString mus = ints().mapToString(); String integer = mus.val(); ``` ```java MockUnitString oddOrEven = ints().mapToString(i -> i%2==0 ? "even" : "odd"); List oddOrEvenList = oddOrEven.list(10).val(); // Possible Output: [odd, even, even, odd, odd, even, even, odd, odd, odd] ``` ``` -------------------------------- ### Generate mock instances with filler() Source: https://www.mockneat.com/docs Uses a Supplier to generate mock instances and set properties using setters, collecting results into a list. ```java List users = filler(() -> new User()) .setter(User::setUserName, users()) .setter(User::setFirstName, names().first()) .setter(User::setLastName, names().last()) .setter(User::setCreated, localDates().thisYear().toUtilDate()) .setter(User::setModified, localDates().thisMonth().toUtilDate()) .list(() -> new ArrayList<>(), 10) // Collecting all the results ina List of 10 elements. .get(); ``` -------------------------------- ### Get single boolean value Source: https://www.mockneat.com/docs Generates a single boolean value with a specific probability using the get method. ```java MockUnit boolUnit = bools().probability(35.50); Boolean val = boolUnit.get(); ``` -------------------------------- ### Generate Map from int[] using mapKeys() Source: https://www.mockneat.com/docs Shows how to create a map by providing an array of keys to the mapKeys() method. ```java int[] keys = { 100, 200, 300, 400, 500, 600 }; Map map = bools().mapKeys(keys).val(); // Possible Output: {400=true, 100=false, 500=false, 200=true, 600=true, 300=true} ``` -------------------------------- ### usStates() Source: https://www.mockneat.com/docs Generates a random US state name or its ISO2 code. Use get() to retrieve a state name and iso2() to get the two-letter code. ```APIDOC ## usStates() ### Description Generates a random US state name or its ISO2 code. ### Method usStates() ### Parameters None ### Returns - **String** - A random US state name when calling get(). - **String** - A random US state ISO2 code when calling iso2().get(). ### Example ```java String usState = usStates().get(); String usStateISO2 = usStates().iso2().get(); ``` ``` -------------------------------- ### Generate credit card using shortcut methods Source: https://www.mockneat.com/docs Uses direct shortcut methods for AMEX, VISA, and MASTERCARD without needing type() or types(). ```java String amex = creditCards().amex().get(); String visa = creditCards().visa().get(); String masterCard = creditCards().masterCard().get(); ``` -------------------------------- ### escapeCsv() Formatting Example Source: https://www.mockneat.com/docs Escapes a string array for CSV compatibility. ```java String[] notFriendlyCsv = { "\"", /* OTHERS */}; String friendlyCSV = from(notFriendlyCsv) .mapToString() .escapeCsv() .val(); ``` -------------------------------- ### Generate Map using Supplier and mapKeys() Source: https://www.mockneat.com/docs Uses a Supplier to instantiate the map, avoiding reflection, while generating keys from a sequence. ```java MockUnitInt keysGenerator = intSeq(); Map namesMap = names() .mapKeys(() -> new LinkedHashMap<>(), keysGenerator.list(10).val()) .val(); System.out.println(namesMap); // Possible Output: // {0=Afton Ragel, 1=Ofelia Labarba, 2=Brian Pezzuti, 3=Hector Starbuck, 4=Kiera Plew, 5=Meta Walling, 6=Trula Steakley, 7=Geoffrey Engelmeyer, 8=Robert Bodnar, 9=Reda Mizzelle} ``` -------------------------------- ### Generate an email with multiple domains using emails().domains() Source: https://www.mockneat.com/docs Generates an email using one of the provided fixed domains. ```java String domsEmail = emails().domains("abc.com", "corp.org").get(); // Possible Output: funjulius@corp.org ``` -------------------------------- ### Generate city names with cities() Source: https://www.mockneat.com/docs Demonstrates generating US cities, world capitals, and European capitals using the cities() method. ```java // Generate a city in the us String city = cities().us().get(); System.out.println(city); // Generate a world capital String worldCapital = cities().capitals().get(); System.out.println(worldCapital); // Generate a capital city in Europe String europeCapital = cities().capitalsEurope().get(); System.out.println(europeCapital); ``` -------------------------------- ### list() Source: https://www.mockneat.com/docs Creates a MockUnit> from a previous MockUnit. Supports specifying a custom List implementation, a Supplier for the list, and a length generator for variable-length lists. ```APIDOC ## list() ### Description Creates a MockUnit> from a previous MockUnit. By default, the implementation used is ArrayList. It supports specifying a custom List implementation class, a Supplier for the list, and a length generator for variable-length lists. ### Method list() ### Parameters - **size** (int) - Required - The fixed number of elements in the list. - **listClass** (Class>) - Optional - The List implementation class to use. Must have a no-args constructor. - **supplier** (Supplier>) - Optional - A supplier that provides a new List instance. - **lengthGenerator** (MockUnitInt) - Optional - A generator that produces variable list lengths. ### Request Example Fixed length with default ArrayList: ```java List countries = countries().names().list(100).val(); ``` Custom List implementation: ```java List countries = countries().names().list(LinkedList.class, 100).val(); ``` Using a Supplier: ```java List emails = emails().list(() -> new ArrayList<>(), 10).val(); ``` Variable length with lengthGenerator: ```java MockUnitInt lengthGenerator = ints().range(1, 100); List creditCards = creditCards().list(() -> new LinkedList<>(), lengthGenerator).val(); ``` ### Response Returns a MockUnit> that can be used to generate a list of values. ### Response Example ``` [Guam, Lao People's Democratic Republic, French Polynesia, Algeria, Somalia, Iraq, ...] ``` ### Notes - For methods that accept a Class>, the List implementation must have a no-args constructor. - The supplier-based overload avoids reflection. ``` -------------------------------- ### constructor() Source: https://www.mockneat.com/docs Generates mock objects by calling the constructor of the target class using reflection. The constructor parameters can be MockUnit objects or constants. ```APIDOC ## constructor() ### Description Generates mock objects by calling the constructor of the target class using reflection. The constructor parameters can be MockUnit objects or constants. ### Method constructor(Class cls) ### Parameters - **cls** (Class) - Required - The class whose constructor will be called. ### Usage ```java public class Test { private String x; private Integer y; private Boolean z; public Test() {} // This is the constructor that is going to be called public Test(String x, Integer y, Boolean z) { this.x = x; this.y = y; this.z = z; } } ``` ```java Test t2 = constructor(Test.class) .params( strings().size(10), ints().range(0, 10), true // constant here ) .get(); // Possible Output: // Test{x='g4bk67PxlT', y=185, z=false} ``` ### Return Value Returns a Constructor object that can be used to generate mock instances. ``` -------------------------------- ### Define Test2 class structure Source: https://www.mockneat.com/docs The class definition for Test2 used in the type override example. ```java public class Test2 { private int x; private int y; private short z; private String w1; private String w2; //.... } //.... ``` -------------------------------- ### factory() Source: https://www.mockneat.com/docs Generates mock objects using static factory methods. Requires a target class and a factory class, then specifies the factory method and its parameters. ```APIDOC ## factory() ### Description Generates mock objects using static factory methods. Requires a target class and a factory class, then specifies the factory method and its parameters. ### Method factory(Class targetClass, Class factoryClass) ### Parameters - **targetClass** (Class) - Required - The class of the object to be generated. - **factoryClass** (Class) - Required - The class containing the static factory method. - **method** (String) - Required - Name of the static factory method. - **params** (Object...) - Required - Parameters for the factory method, which can be MockNeat generators or literal values. ### Request Example ```java Test t3 = factory(Test.class, TestFactory.class) .method("buildTest") .params(strings(), 1, true) .get(); // Possible Output: Test{x='6pmmWFiAEPW35dUj9sjcnOaglfXO7hIoyu38UK395pZ8Ns1dPJSkpz0Sg0C4IVVA', y=1, z=true} ``` ### Response Returns an instance of the target class created by the specified factory method. ``` -------------------------------- ### Generate random LocalDate between two dates Source: https://www.mockneat.com/docs Generates a random LocalDate between a start and stop date. ```java LocalDate start = LocalDate.of(1989, 1, 1); LocalDate stop = LocalDate.of(1993, 1, 1); LocalDate between = localDates().between(start, stop).get(); // Possible Output: 1989-02-04 ``` -------------------------------- ### Generate country ISO2 codes with countries() Source: https://www.mockneat.com/docs Shows how to generate a random country ISO2 code. ```java String iso2 = countries().iso2().get(); // Possible Output: MR ``` -------------------------------- ### Generate country names with countries() Source: https://www.mockneat.com/docs Shows how to generate a random country name. ```java String countryName = countries().names().get(); // Possible Output: Lithuania ``` -------------------------------- ### get() Source: https://www.mockneat.com/docs Returns a single value of type T from the MockUnit. This is a Scala and Kotlin friendly alias for the val() method. ```APIDOC ## get() ### Description Returns a single value of type T from the MockUnit. This method is a Scala and Kotlin friendly alias for the val() method. ### Method get() ### Parameters None. ### Request Example ```java MockUnit boolUnit = bools().probability(35.50); Boolean val = boolUnit.get(); ``` Simpler form: ```java Boolean val = bools().probability(35.50).get(); ``` ### Response Returns a single value of type T. ### Response Example A Boolean value (e.g., true or false). ``` -------------------------------- ### Translate MockUnit to MockUnit using map() Source: https://www.mockneat.com/docs Demonstrates using map() to transform boolean values into their string representations. ```java List list = bools().map((b) -> b.toString()).list(10).val(); ``` -------------------------------- ### Generate car models and brands with cars() Source: https://www.mockneat.com/docs Generates lists of car models or specific car brands. ```java cars().list(1000).consume(System.out::println); // Brands only (e.g: "Dacia") cars().brands().list(100).consume(System.out::println); ``` -------------------------------- ### mapToLocalDate() Source: https://www.mockneat.com/docs Transforms a MockUnit into a MockUnitLocalDate using a Function. The example shows generating local dates only in 1987 or 1989. ```APIDOC ## mapToLocalDate() ### Description Transforms a MockUnit into a more specific MockUnitLocalDate using a Function. ### Method mapToLocalDate ### Parameters - **function** (Function) - Required - The function that maps a value of type T to a LocalDate. ### Example ```java // Generates local dates only in 1987 or in 1989 ints().from(new int[]{ 1987, 1989}) .mapToLocalDate(year -> { // Obtain a random month [1, 12] int month = ints() .range(1, 13) .get(); // Check how many days the month has for that year int numDays = YearMonth.of(year, month).lengthOfMonth(); // Generate a random day int day = ints() .range(1, numDays + 1) .get(); return java.time.LocalDate.of(year, month, day); }) .display(BASIC_ISO_DATE) .accumulate(100, "\n") .consume(System.out::println); ``` ### Returns MockUnitLocalDate - A MockUnit that generates LocalDate values. ``` -------------------------------- ### Generate mock objects with constructor() Source: https://www.mockneat.com/docs Uses the constructor() method to instantiate a Test object with randomized parameters. ```java Test t2 = constructor(Test.class) .params( strings().size(10), ints().range(0, 10), true // constant here ) .get(); // Possible Output: // Test{x='g4bk67PxlT', y=185, z=false} ``` -------------------------------- ### creditCards().types(CreditCardType...) Source: https://www.mockneat.com/docs Generates a credit card number that can be one of the specified types. For example, VISA_16 or MASTERCARD. ```APIDOC ## creditCards().types(CreditCardType...) ### Description Generates a credit card number that can be one of the specified types. For example, VISA_16 or MASTERCARD. ### Method creditCards().types(CreditCardType... types) ### Parameters - **types** (CreditCardType...) - Required - The possible credit card types to generate. ### Request Example ```java String visaOrMastercard = creditCards() .types(VISA_16, MASTERCARD) .get(); ``` ### Response Returns a String representing a valid credit card number of one of the specified types. ``` -------------------------------- ### MockUnitDays.display() Source: https://www.mockneat.com/docs Generates a MockUnitString from a MockUnitDays by transforming the day of week into a localized string. There are three overloads: one with explicit TextStyle and Locale, one with only TextStyle using the default locale, and one with default TextStyle (FULL_STANDALONE) and default locale. ```APIDOC ## MockUnitDays.display() ### Description Generates a MockUnitString from a MockUnitDays by transforming the day of week into a localized string. There are three overloads: one with explicit TextStyle and Locale, one with only TextStyle using the default locale, and one with default TextStyle (FULL_STANDALONE) and default locale. ### Method - display(TextStyle textStyle, Locale locale) - display(TextStyle textStyle) - display() ### Parameters #### display(TextStyle textStyle, Locale locale) - **textStyle** (TextStyle) - Required - The text style to use for the day name (e.g., FULL_STANDALONE). - **locale** (Locale) - Required - The locale to use for localization. #### display(TextStyle textStyle) - **textStyle** (TextStyle) - Required - The text style to use for the day name. #### display() - No parameters. ### Return Value - **MockUnitString** - A MockUnitString that generates a localized day-of-week string. ### Example ```java String day = days() .after(FRIDAY) .display(TextStyle.FULL_STANDALONE, Locale.FRANCE) .val(); // Possible Output: "dimanche" ``` ``` -------------------------------- ### Generate random day of the week-end in French Source: https://www.mockneat.com/docs Example of generating a String that represents a random day of the week-end in French using display(). ```java String day = days() .after(FRIDAY) .display(TextStyle.FULL_STANDALONE, Locale.FRANCE) .val(); // Possible Output: "dimanche" ``` -------------------------------- ### creditCards().type(CreditCardType) Source: https://www.mockneat.com/docs Generates a credit card number of the specified type. For example, VISA_16 generates a 16-digit VISA card. ```APIDOC ## creditCards().type(CreditCardType) ### Description Generates a credit card number of the specified type. For example, VISA_16 generates a 16-digit VISA card. ### Method creditCards().type(CreditCardType type) ### Parameters - **type** (CreditCardType) - Required - The credit card type to generate. ### Request Example ```java String visa16 = creditCards().type(VISA_16).get(); ``` ### Response Returns a String representing a valid credit card number of the specified type. ``` -------------------------------- ### MockUnitDays display method signatures Source: https://www.mockneat.com/docs Method signatures for the display() method in MockUnitDays. ```java default MockUnitString display(TextStyle textStyle, Locale locale) ``` ```java default MockUnitString display(TextStyle textStyle) ``` ```java default MockUnitString display() ``` -------------------------------- ### longSeq() Source: https://www.mockneat.com/docs Generates a sequence of long numbers. Supports configuring the starting value, increment, maximum or minimum value, and cycling behavior. ```APIDOC ## longSeq() ### Description Generates a sequence of long numbers. The sequence can be configured with a starting value, an increment (positive or negative), a maximum or minimum bound, and whether to cycle back to the start when the bound is reached. ### Method longSeq() ### Parameters #### Optional Chaining Methods - **start(long start)** - Optional - Sets the starting value of the sequence. Default is 0. - **increment(long increment)** - Optional - Sets the increment between successive values. Default is 1. - **max(long max)** - Optional - Sets the maximum value (exclusive) for the sequence. When the sequence reaches a value greater than this, it resets to the start value. Default is Long.MAX_VALUE. - **min(long min)** - Optional - Sets the minimum value (exclusive) for the sequence when using negative increments. When the sequence reaches a value less than this, it resets to the start value. Default is Long.MIN_VALUE. - **cycle(boolean cycle)** - Optional - If true, the sequence cycles back to the start value when the bound is reached. Default is false. ### Return Value - **LongSeq** - A sequence object that can be iterated using get(). ### Examples ```java LongSeq seq = longSeq(); for(int i = 0; i < 20; i++) { System.out.print(seq.get() + " "); } // Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 LongSeq seq2 = longSeq() .start(5) .increment(2) .max(20) .cycle(true); for(int i = 0; i < 50; i++) { System.out.print(seq2.get() + " "); } // Output: 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 9 11 13 15 17 19 5 7 ``` ``` -------------------------------- ### fmt() Source: https://www.mockneat.com/docs Generates a formatted String by replacing named parameters (e.g., #{param}) with random values from provided MockUnits or constant strings. ```APIDOC ## fmt() ### Description Generates a formatted String by replacing named parameters (e.g., #{param}) with random values from provided MockUnits or constant strings. ### Method fmt() ### Parameters - **param** (String) - Required - The name of the parameter to replace in the template. - **value** (MockUnit or String) - Required - The MockUnit or constant string used to generate the replacement value. ### Request Example ```java String temp = "{#{d1}#{d2}#{l1}#{sc}"; String result = fmt(templ) .param("d1", chars().digits()) .param("d2", chars().digits()) .param("l1", chars().letters()) .param("sc", from(SPECIAL_CHARACTERS)) .get(); ``` ### Response Returns a String with the named parameters replaced by generated values. ### Response Example ``` // Possible Output: 45q' ``` ``` -------------------------------- ### Generate random URLs with configuration Source: https://www.mockneat.com/docs Configures and generates a list of 10 random URLs with specific schemes, domains, hosts, and ports. ```java urls() .scheme(HTTP) // all the URLS have a HTTP scheme //.auth() -- can include auth information in the URL .domain(POPULAR) // only popular domain names can be used .host(ADVERB_VERB) .ports(80, 8080, 8090) // only the following ports can be used .list(10) .consume(System.out::println); ``` ```text [http://www.tenthlyassays.net:8090, http://www.aflamecurr.io:8080, http://www.thirdlygirth.org:8080, http://www.foreprobates.net:8090, http://www.pokilyrile.org:80, http://www.cheerfullyapprizings.net:8090, http://www.whistlinglyunsettles.info:80, http://www.gratistrichinized.io:8080, http://www.sternwardssnuffle.gov:8090, http://www.yesterdaynix.edu:8090] ``` -------------------------------- ### Get single boolean value inline Source: https://www.mockneat.com/docs Generates a single boolean value with a specific probability without storing the intermediate unit reference. ```java Boolean val = bools().probability(35.50).get(); ``` -------------------------------- ### Generate formatted string with fmt() Source: https://www.mockneat.com/docs Generates a random string based on a template with named parameters. Parameters can be MockUnits or constant strings. ```java String temp = "{#{d1}#{d2}#{l1}#{sc}"; String result = fmt(templ) .param("d1", chars().digits()) .param("d2", chars().digits()) .param("l1", chars().letters()) .param("sc", from(SPECIAL_CHARACTERS)) .get(); // Possible Output: 45q' ``` -------------------------------- ### base64() Source: https://www.mockneat.com/docs Encodes each generated string to Base64. ```APIDOC ## base64() ### Description Encodes each generated string to Base64. ### Method base64() ### Returns MockUnitString - A MockUnitString that produces Base64-encoded strings. ### Example ```java List base64names = seq(names) .mapToString() .base64() .list(5) .val(); ``` ``` -------------------------------- ### mapToInt() Source: https://www.mockneat.com/docs Translates a MockUnit into a MockUnitInt using a Function. The example shows converting a MockUnit to 1 for true and 0 for false. ```APIDOC ## mapToInt() ### Description Translates a MockUnit into a more specific MockUnitInt using a Function. ### Method mapToInt ### Parameters - **function** (Function) - Required - The function that maps a value of type T to an Integer. ### Example ```java MockUnitInt zeroOrOne = bools() .mapToInt((b) -> (b) ? 1 : 0); List list = zeroOrOne.list(5).val(); // Possible Output: [0, 0, 0, 1, 0] ``` ### Returns MockUnitInt - A MockUnit that generates Integer values. ``` -------------------------------- ### Generate integer matrix with array() Source: https://www.mockneat.com/docs Generates a matrix of integers with 5 rows and 5 columns. ```java int[][] a = ints() .arrayPrimitive(5) .array(int[].class, 10) .val(); ``` -------------------------------- ### collection() Source: https://www.mockneat.com/docs Generates a MockUnit> from a MockUnit. Supports reflection-based collection creation (requires a public no-args constructor) or a Supplier> for custom collection creation. The size can be fixed or variable. ```APIDOC ## collection() ### Description Generates a MockUnit> from a MockUnit. The collection type can be specified via reflection (must have a public no-args constructor) or via a Supplier>. The size can be a fixed integer or a MockUnitInt for variable length. ### Method collection() ### Parameters - **collectionClass** (Class) - Required - The collection class to instantiate (must have a public no-args constructor). - **size** (int) - Required - The number of elements in the collection. - **supplier** (Supplier>) - Optional - A supplier that provides the collection instance, used instead of reflection. - **sizeGenerator** (MockUnitInt) - Optional - A MockUnitInt that generates the size of the collection, allowing variable length. ### Return Value MockUnit> - A MockUnit that generates a collection of type Collection with the specified size. ### Examples Generate a Vector of size 100 with 35.5% probability of true: ```java Collection vector = bools() .probability(35.50) .collection(Vector.class, 100) .val(); ``` Generate a Collection (Stack implementation) with 10 values: ```java Collection c = bools().collection(() -> new Stack<>(), 10).val(); ``` Generate a Collection with variable length in range [0, 10): ```java MockUnitInt sizeGenerator = ints().range(0, 10); Collection cStr = strings().collection(() -> new ArrayList<>(), sizeGenerator).val(); ``` ``` -------------------------------- ### Generate MockUnitString with mapToString Source: https://www.mockneat.com/docs Demonstrates using mapToString without parameters to call toString() on generated objects. ```java MockUnitString mus = ints().mapToString(); String integer = mus.val(); ``` -------------------------------- ### Generate a 3-digit CVV with cvvs().get() Source: https://www.mockneat.com/docs By default, cvvs() uses the CVV3 type, generating a 3-digit random string. This example shows the simplest usage. ```java String cvv = cvvs().get(); ``` -------------------------------- ### Generate numbers in intervals with probabilities() Source: https://www.mockneat.com/docs Uses MockUnit parameters to generate numbers within specific intervals based on assigned probabilities. ```java Integer x = probabilites(Integer.class) .add(0.2, ints().range(0, 100)) .add(0.5, ints().range(100, 200)) .add(0.3, ints().range(200, 300)) .get(); ``` -------------------------------- ### longs() Source: https://www.mockneat.com/docs Generates random long numbers. Supports unbounded generation, bounded generation in the range [0, bound), and ranged generation in the range [start, end). ```APIDOC ## longs() ### Description Generates random long numbers. Can generate unbounded values, values bounded by a maximum (exclusive), or values within a specified range (exclusive upper bound). ### Method longs() ### Parameters #### Optional Chaining Methods - **bound(long bound)** - Optional - Sets the upper bound (exclusive) for generated values. Generates values in the range [0, bound). - **range(long start, long end)** - Optional - Sets the inclusive lower and exclusive upper bounds for generated values. Generates values in the range [start, end). ### Return Value - **Long** - A randomly generated long value. ### Examples ```java Long i1 = longs().get(); // Possible Output : -2445487402940283422 Long bounded = longs().bound(10).get(); // Possible Output: 8 Long ranged = longs().range(10, 20).get(); // Possible Output: 19 ``` ``` -------------------------------- ### Generate Forex pair with currencies().forexPair() Source: https://www.mockneat.com/docs Returns a random common Forex pair string. ```java String forexPair = currencies().forexPair().get(); ``` -------------------------------- ### mapToLong() Source: https://www.mockneat.com/docs Translates a MockUnit into a MockUnitLong by applying a Function to each generated value. The example shows converting a MockUnit> to a MockUnitLong by summing the list elements. ```APIDOC ## mapToLong() ### Description Translates a MockUnit into a MockUnitLong using a Function. ### Method mapToLong(Function) ### Parameters - **function** (Function) - Required - The function that converts a generated value of type T to a Long. ### Returns MockUnitLong - A mock unit that generates Long values. ### Example ```java MockUnit> muList = longs() .range(0l, 100l) .list(10); Long sum = muList.mapToLong(list -> list.stream() .mapToLong(Long::longValue) .sum()) .val(); ``` ``` -------------------------------- ### fromKeys() Source: https://www.mockneat.com/docs Returns a random key from a Map. The keys are copied internally into an array, and then a random key is picked from that array. ```APIDOC ## fromKeys() ### Description Returns a random key from a Map. The keys are copied internally into an array, and then a random key is picked from that array. ### Method fromKeys() ### Parameters - **map** (Map) - Required - The map from which to pick a random key. ### Request Example ```java // Example usage (not provided in source) ``` ### Response Returns a random key from the provided map. ### Response Example ``` // Not provided in source ``` ``` -------------------------------- ### Generate Map objects with objectMap() Source: https://www.mockneat.com/docs Creates a Map structure, useful for JSON generation. The example shows nested maps and random data generation. ```java Map map = objectMap() .put("name", names().last()) .put("age", ints().range(10, 100)) .put("inner", objectMap().put("actors", actors().set(10)) ) .get(); System.out.println(map); ``` ```text {name=Rockovich, inner={actors=[Byung-Hun Lee, Takeshi Kitano, Bob Hoskins, Ed Helms, Paul Giamatti, Mike Myers, Thomas Haden Church, Chris O'Donnell, Henry Fonda, John Travolta]}, age=28} ``` -------------------------------- ### words() Source: https://www.mockneat.com/docs Generates random English words. Supports various grammatical categories (adverbs, adjectives, nouns, verbs) and syllable counts (1-4). Use get() to retrieve a random word. ```APIDOC ## words() ### Description Generates random English words. Supports various grammatical categories (adverbs, adjectives, nouns, verbs) and syllable counts (1-4). Use get() to retrieve a random word. ### Method words() ### Parameters None ### Returns - **String** - A random English word when calling get(). ### Variants - **words().adverbs()** - Returns an arbitrary adverb. - **words().adverbs1syll()** - Returns an arbitrary 1-syllable adverb. - **words().adverbs2syll()** - Returns an arbitrary 2-syllable adverb. - **words().adverbs3syll()** - Returns an arbitrary 3-syllable adverb. - **words().adverbs4syll()** - Returns an arbitrary 4-syllable adverb. - **words().adjectives()** - Returns an arbitrary adjective. - **words().adjectives1syll()** - Returns an arbitrary 1-syllable adjective. - **words().adjectives2syll()** - Returns an arbitrary 2-syllable adjective. - **words().adjectives3syll()** - Returns an arbitrary 3-syllable adjective. - **words().adjectives4syll()** - Returns an arbitrary 4-syllable adjective. - **words().nouns()** - Returns an arbitrary noun. - **words().nouns1syll()** - Returns an arbitrary 1-syllable noun. - **words().nouns2syll()** - Returns an arbitrary 2-syllable noun. - **words().nouns3syll()** - Returns an arbitrary 3-syllable noun. - **words().nouns4syll()** - Returns an arbitrary 4-syllable noun. - **words().verbs()** - Returns an arbitrary verb. - **words().verbs1syll()** - Returns an arbitrary 1-syllable verb. - **words().verbs2syll()** - Returns an arbitrary 2-syllable verb. - **words().verbs3syll()** - Returns an arbitrary 3-syllable verb. - **words().verbs4syll()** - Returns an arbitrary 4-syllable verb. ### Example ```java String word = words().get(); ``` ### Example with formatting ```java fmt("#{adj} #{noun}") .param("adj", words().adjectives().format(CAPITALIZED)) .param("noun", words().nouns().format(LOWER_CASE)) .list(10) .consume(list -> System.out.println(list)); ``` ``` -------------------------------- ### Generate MD5 hash with hashes().md5() Source: https://www.mockneat.com/docs Generates a MD5 hash from a random string. ```java String str = hashes().md5().get(); ``` -------------------------------- ### mapKeys() Source: https://www.mockneat.com/docs Generates a MockUnit> from a MockUnit. Keys can be obtained from another MockUnit, Supplier, Iterable, generic array, or primitive arrays. ```APIDOC ## mapKeys() ### Description Generates a MockUnit> from a MockUnit. Keys can be obtained from another MockUnit, Supplier, Iterable, generic array, or primitive arrays. ### Method mapKeys() ### Parameters - **keys** (MockUnit, Supplier, Iterable, R[], int[], double[], long[]) - Required - The source of keys for the map. - **mapSupplier** (Supplier>) - Optional - A supplier to avoid reflection-based map instantiation. ### Examples ```java int[] keys = { 100, 200, 300, 400, 500, 600 }; Map map = bools().mapKeys(keys).val(); ``` ```java Iterable iterable = unmodifiableList(asList(0.1, 0.2, 0.3, 0.4, 0.5)); Map map = bools().mapKeys(LinkedHashMap.class, iterable).val(); ``` ```java MockUnitInt keysGenerator = intSeq(); Map namesMap = names() .mapKeys(() -> new LinkedHashMap<>(), keysGenerator.list(10).val()) .val(); ``` ``` -------------------------------- ### Generate currency name with currencies().name() Source: https://www.mockneat.com/docs Returns a random currency name from around the world. ```java String currencyName = currencies().name().get(); ```