{"id":18684658,"url":"https://github.com/hippoom/test-data-builder","last_synced_at":"2025-10-17T05:21:51.712Z","repository":{"id":57719976,"uuid":"104641469","full_name":"Hippoom/test-data-builder","owner":"Hippoom","description":"A tiny library to simplify test data building.","archived":false,"fork":false,"pushed_at":"2018-04-18T03:02:54.000Z","size":94,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-27T23:56:36.112Z","etag":null,"topics":["data-builder","test-data-generator","test-driven-development"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hippoom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-24T12:16:29.000Z","updated_at":"2024-07-21T03:34:27.000Z","dependencies_parsed_at":"2022-09-26T21:41:12.830Z","dependency_job_id":null,"html_url":"https://github.com/Hippoom/test-data-builder","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hippoom%2Ftest-data-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hippoom%2Ftest-data-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hippoom%2Ftest-data-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hippoom%2Ftest-data-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hippoom","download_url":"https://codeload.github.com/Hippoom/test-data-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239539152,"owners_count":19655735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-builder","test-data-generator","test-driven-development"],"created_at":"2024-11-07T10:18:46.215Z","updated_at":"2025-10-17T05:21:46.679Z","avatar_url":"https://github.com/Hippoom.png","language":"Java","readme":"# test-data-builder\n[![Build Status](https://travis-ci.org/Hippoom/test-data-builder.svg?branch=master)](https://travis-ci.org/Hippoom/test-data-builder)[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.hippoom/test-data-builder/badge.png)](https://maven-badges.herokuapp.com/maven-central/com.github.hippoom/test-data-builder)\nA tiny library to simplify test data building.\n\n## Installation\nYou can download the binary from [Maven Central Repository](http://mvnrepository.com/artifact/com.github.hippoom/test-data-builder).\n\n\n## Usage\n######  Building a List of test data\n\nIt is easy to build a list of test data with the static factory method`listOfSize`:\n\n```java\nimport static com.github.hippoom.tdb.GenericTestDataListBuilder.listOfSize;\n\nList\u003cOrder\u003e orders = listOfSize(5, // (1)\n    sequence -\u003e new OrderBuilder() // (2)\n).build();                         // (3)\n```\n\n\u003e (1) declaring the list should contain 5 elements\n\u003e\n\u003e (2) a default `Function\u003cInteger, OrderBuilder\u003e` takes list sequence (starts from 1) and returns a data builder, the function will be used to generate a default value for each element\n\u003e\n\u003e (3) building the list, it calls `OrderBuild.build()` by default  to generate `Order`\n\n\n\n###### Customizing the element differs\n\nNow each element has a default value,  you just customize the element differ in the current test case:\n\n```java\nimport static com.github.hippoom.tdb.GenericTestDataListBuilder.listOfSize;\nimport static com.github.hippoom.tdb.Location.IN_STORE\nimport static com.github.hippoom.tdb.Location.TAKE_AWAY\n\nList\u003cOrder\u003e orders = listOfSize(5, sequence -\u003e new OrderBuilder())\n    \t\t\t\t\t.theFirst(2, builder -\u003e builder.is(TAKE_AWAY)) // (1)\n    \t\t\t\t\t.number(3, builder -\u003e builder.is(IN_STORE))    // (2)\n    \t\t\t\t\t.theLast(2, builder -\u003e builder.paid())         // (3)\n    \t\t\t\t\t.build();\n```\n\n\u003e (1) declaring the first two elements apply a `Function\u003cOrderBuilder, OrderBuilder\u003e` that customizes the element\n\u003e\n\u003e (2) declaring the third element in the list applies a `Function\u003cOrderBuilder, OrderBuilder\u003e` \n\u003e\n\u003e (3)  declaring the last two elements apply a `Function\u003cOrderBuilder, OrderBuilder\u003e` \n\n\n\n###### Customizing the multiple elements with `number()`\n\nSometimes you want to customize multiple elements in the middle of the list. The `number()` has a overloaded variation to help you:\n\n```java\nimport static com.github.hippoom.tdb.GenericTestDataListBuilder.listOfSize;\nimport static com.github.hippoom.tdb.Location.TAKE_AWAY\n\nList\u003cOrder\u003e orders = listOfSize(5, sequence -\u003e new OrderBuilder())\n    \t\t\t\t\t.number(2, 4).apply(builder -\u003e builder.is(TAKE_AWAY)) // (1)\n    \t\t\t\t\t.build();\n```\n\u003e (1) declaring the second and fourth element should apply a `Function\u003cOrderBuilder, OrderBuilder\u003e` that customizes the element\n\n\n###### Customizing the multiple elements with `all()`\n\nSometimes you want to customize all elements. The `all()` can help you:\n\n```java\nimport static com.github.hippoom.tdb.GenericTestDataListBuilder.listOfSize;\nimport static com.github.hippoom.tdb.Location.TAKE_AWAY\n\nList\u003cOrder\u003e orders = listOfSize(5, sequence -\u003e new OrderBuilder())\n    \t\t\t\t\t.all().apply(builder -\u003e builder.is(TAKE_AWAY)) // (1)\n    \t\t\t\t\t.build();\n```\n\u003e (1) declaring all elements should apply a `Function\u003cOrderBuilder, OrderBuilder\u003e` that customizes the element\n\nYou can also use the variation `all(Function\u003cT, T\u003e function)`:\n\n```java\nimport static com.github.hippoom.tdb.GenericTestDataListBuilder.listOfSize;\nimport static com.github.hippoom.tdb.Location.TAKE_AWAY;\n\nList\u003cOrder\u003e orders = listOfSize(5, sequence -\u003e new OrderBuilder())\n    \t\t\t\t\t.all(builder -\u003e builder.is(TAKE_AWAY)) // (1)\n    \t\t\t\t\t.build();\n```\n\u003e (1) declaring all elements should apply a `Function\u003cOrderBuilder, OrderBuilder\u003e` that customizes the element\n\n###### Customizing the multiple elements with `allWithSeq()`\n\nSometimes you want to customize all elements but with dynamic data based on the sequence of the element (starts from 1). \nThe `allWithSeq()` can help you:\n\n```java\nimport static com.github.hippoom.tdb.GenericTestDataListBuilder.listOfSize;\nimport static com.github.hippoom.tdb.Location.TAKE_AWAY;\n\nList\u003cOrder\u003e orders = listOfSize(5, sequence -\u003e new OrderBuilder())\n    \t\t\t\t\t.allWithSeq(builder, seq -\u003e builder.withId(seq)) // (1)\n    \t\t\t\t\t.build();\n```\n\u003e (1) declaring all elements should apply a `BiFunction\u003cOrderBuilder, Integer, OrderBuilder\u003e` that customizes the element\n\n\n###### What if I want to customize a range of consecutive elements in the middle of the list\n\n```java\nimport static com.github.hippoom.tdb.GenericTestDataListBuilder.listOfSize;\nimport static com.github.hippoom.tdb.Location.TAKE_AWAY;\n\nList\u003cOrder\u003e orders = listOfSize(5, sequence -\u003e new OrderBuilder())\n    \t\t\t\t\t.range(2, 4).apply(builder -\u003e builder.is(TAKE_AWAY)) // (1)\n    \t\t\t\t\t.build();\n```\n\n\u003e (1) declaring from the second(inclusive) to the fourth(inclusive) elements should apply a `Function\u003cOrderBuilder, OrderBuilder\u003e` that customizes the element\n\n\n###### What if the Builder has a different build method other than `build()`\n```java\nimport static com.github.hippoom.tdb.GenericTestDataListBuilder.listOfSize;\n\nList\u003cOrder\u003e orders = listOfSize(5, sequence -\u003e new OrderBuilder())\n    \t\t\t\t\t.build(builder -\u003e builder.anotherBuild()); //(1)\n```\n\u003e (1) calls `anotherBuild()` instead of `build()` to generate the elements\n\n\n\n## License\n\nLicensed under Apache License (the \"License\"); You may obtain a copy of the License in the LICENSE file, or at [here](https://github.com/Hippoom/test-data-builder/blob/master/LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhippoom%2Ftest-data-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhippoom%2Ftest-data-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhippoom%2Ftest-data-builder/lists"}