Releases: instancio/instancio
5.4.1
What's Changed
- It allows the generated number to be very close to or even equal to the limits configured for the interval by @neibarbosa in #1304
- Bump com.puppycrawl.tools:checkstyle from 10.21.2 to 10.21.3 by @dependabot in #1306
- Bump org.junit:junit-bom from 5.11.4 to 5.12.0 by @dependabot in #1305
- Bump org.apache.maven.plugins:maven-compiler-plugin from 3.13.0 to 3.14.0 by @dependabot in #1308
- Bump org.apache.maven.plugins:maven-deploy-plugin from 3.1.3 to 3.1.4 by @dependabot in #1310
- Bump org.slf4j:slf4j-api from 2.0.16 to 2.0.17 by @dependabot in #1309
- Bump org.apache.groovy:groovy from 4.0.25 to 4.0.26 by @dependabot in #1311
- Bump com.fasterxml.jackson.core:jackson-databind from 2.18.2 to 2.18.3 by @dependabot in #1312
- Bump com.puppycrawl.tools:checkstyle from 10.21.3 to 10.21.4 by @dependabot in #1314
- Bump com.github.spotbugs:spotbugs-maven-plugin from 4.9.1.0 to 4.9.2.0 by @dependabot in #1313
- Bump version.jooq from 3.19.18 to 3.19.21 by @dependabot in #1319
- Bump nl.jqno.equalsverifier:equalsverifier-nodep from 3.19.1 to 3.19.2 by @dependabot in #1321
- Bump org.junit:junit-bom from 5.12.0 to 5.12.1 by @dependabot in #1323
- Bump com.github.spotbugs:spotbugs-maven-plugin from 4.9.2.0 to 4.9.3.0 by @dependabot in #1322
- Bug fix: NPE with bean validation enabled and nullable object (#1324) by @armandino in #1326
New Contributors
- @neibarbosa made their first contribution in #1304
Full Changelog: instancio-parent-5.4.0...instancio-parent-5.4.1
5.4.0
What's Changed
New Features
- Support for Groovy method reference selectors (thanks to @nstdio) #1280
- Support for generating random values using
oneOf().orRandom()
#1288
- Bump org.jetbrains:annotations from 26.0.1 to 26.0.2 by @dependabot in #1275
- Bump com.puppycrawl.tools:checkstyle from 10.21.1 to 10.21.2 by @dependabot in #1277
- Support
Select.field(GetMethodSelector)
for Groovy by @nstdio in #1280 - Bug fix: bean validation uses default
Settings
by @armandino in #1283 - Bump nl.jqno.equalsverifier:equalsverifier-nodep from 3.18.1 to 3.18.2 by @dependabot in #1282
- Bump jakarta.validation:jakarta.validation-api from 3.1.0 to 3.1.1 by @dependabot in #1285
- Bump nl.jqno.equalsverifier:equalsverifier-nodep from 3.18.2 to 3.19 by @dependabot in #1286
- Bump com.tngtech.archunit:archunit from 1.3.0 to 1.4.0 by @dependabot in #1287
- Support for generating random values using
oneOf().orRandom()
by @armandino in #1288 - Add groovy test by @armandino in #1289
- Fixed a state leak caused by a mutable collection by @armandino in #1294
- Bump version.kotlin from 2.1.0 to 2.1.10 by @dependabot in #1279
- Bump com.github.spotbugs:spotbugs-maven-plugin from 4.8.6.6 to 4.9.1.0 by @dependabot in #1296
- Bump nl.jqno.equalsverifier:equalsverifier-nodep from 3.19 to 3.19.1 by @dependabot in #1299
- Bump version.jooq from 3.19.18 to 3.20.0 by @dependabot in #1300
- Revert "Bump version.jooq from 3.19.18 to 3.20.0" by @armandino in #1301
New Contributors
Full Changelog: instancio-parent-5.3.0...instancio-parent-5.4.0
5.3.0
What's Changed
New Features
-
New top-level APIs
Instancio.fill(T)
andInstancio.ofObject(T)
(#1268)Example: given a partially populated object:
class Person { String name; String email; LocalDate dateOfBirth; // getters/setters } Person person = new Person(); person.setDateOfBirth(LocalDate.of(1980, 12, 31)); // The remaining fields can be populated as follows: Instancio.fill(person); // Sample output: // Person[name=VCNSOU email=ONVERFS, dateOfBirth=1980-12-31]
Additionally, the
ofObject()
builder API supports all of the usual Instancio methods:Person person = new Person(); person.setDateOfBirth(LocalDate.of(1980, 12, 31)); Instancio.ofObject(person) .generate(field(Person::getEmail), gen -> gen.net().email()) .fill(); // Sample output: // Person[name=VCNSOU, email=fphna@mph.org, dateOfBirth=1980-12-31]
Bug Fixes
- Overwrite initialised field via
assign()
(#1253)
Breaking Changes
- Experimental API breaking change: renamed
@DataSpec
to@AliasSpec
(#1244)
- Bump com.puppycrawl.tools:checkstyle from 10.20.2 to 10.21.0 by @dependabot in #1243
- Experimental API breaking change: renamed
@DataSpec
to@AliasSpec
by @armandino in #1244 - Bump org.junit:junit-bom from 5.11.3 to 5.11.4 by @dependabot in #1249
- Bump com.google.guava:guava from 33.3.1-jre to 33.4.0-jre by @dependabot in #1248
- Upgrade assertj to 3.27.0 by @armandino in #1251
- Bug fix: overwrite initialised field via
assign()
by @armandino in #1253 - Bump nl.jqno.equalsverifier:equalsverifier-nodep from 3.17.5 to 3.18 by @dependabot in #1254
- Cleanup tests by @armandino in #1255
- Cleanup tests cont'd by @armandino in #1256
- Refactor: cleanup handling of selector targets to remove
instanceof
checks by @armandino in #1257 - Refactor: renamed util method by @armandino in #1258
- Bump com.puppycrawl.tools:checkstyle from 10.21.0 to 10.21.1 by @dependabot in #1259
- Updated license headers by @armandino in #1260
- Bump org.assertj:assertj-bom from 3.27.0 to 3.27.1 by @dependabot in #1261
- Bump org.assertj:assertj-bom from 3.27.1 to 3.27.2 by @dependabot in #1262
- Bump version.jooq from 3.19.16 to 3.19.17 by @dependabot in #1264
- Bump nl.jqno.equalsverifier:equalsverifier-nodep from 3.18 to 3.18.1 by @dependabot in #1266
- Bump com.github.siom79.japicmp:japicmp-maven-plugin from 0.23.0 to 0.23.1 by @dependabot in #1265
- Bump version.jooq from 3.19.17 to 3.19.18 by @dependabot in #1269
- New top-level APIs
Instancio.fill(T)
andInstancio.ofObject(T)
(#1252) by @armandino in #1268 - Updated build to use java 23 by @armandino in #1270
- Refactor: cleanup error message creation by @armandino in #1271
- Bump org.assertj:assertj-bom from 3.27.2 to 3.27.3 by @dependabot in #1272
Full Changelog: instancio-parent-5.2.1...instancio-parent-5.3.0
5.2.1
What's Changed
Bug Fixes
Generating numbers based on bean validation constraints (#1240)
- Refactored node related classes by @armandino in #1230
- Refactored
ModelContext
and related internal classes by @armandino in #1231 - Refactor: simplify things by removing the
NodeContext
class by @armandino in #1232 - Cleanup of method signatures by @armandino in #1233
- Refactor: re-org bean validation classes by @armandino in #1234
- Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.1 to 3.11.2 by @dependabot in #1235
- Bump nl.jqno.equalsverifier:equalsverifier-nodep from 3.17.4 to 3.17.5 by @dependabot in #1236
- Float and double generator improvements by @armandino in #1237
- Refactored numeric generators and tests by @armandino in #1238
- Refactored Hibernate bean validation tests to use the
@Given
annotation by @armandino in #1239 - Bug fix: generating numbers based on bean validation constraints (#1150) by @armandino in #1240
- Bump version.jooq from 3.19.15 to 3.19.16 by @dependabot in #1241
Full Changelog: instancio-parent-5.2.0...instancio-parent-5.2.1
5.2.0
What's Changed
New Features
wordTemplate()
spec that supports noun, verb, adjective, and adverb placeholders (#1220)
A spec for generating text based on a template containing placeholders, such as ${noun}
, ${verb}
, ${adjective}
, and ${adverb}
.
Example:
record Company(String website) {}
List<Company> companies = Instancio.ofList(Company.class)
.size(3)
.generate(field(Company::website), gen -> gen.text().wordTemplate("${adjective}-${noun}.com"))
.create();
// Sample output:
[[Company[website=global-bidder.com],
Company[website=independent-beat.com],
Company[website=promotional-clock.com]]
The placeholders are case-sensitive and support three case styles for the output:
${noun}
- Outputs a lowercase word e.g. "cat"${Noun}
- Outputs a capitalised word e.g. "Cat"${NOUN}
- Outputs an uppercase word e.g. "CAT"
Throw an error by default if applyFeed()
has unmapped feed properties (#1225)
This is a potential breaking change to an experimental API. The original behaviour can restored by the new setting Keys.ON_FEED_PROPERTY_UNMATCHED
which can be used to ignore unmapped feed properties.
Bug Fixes
Only report the initial seed for @InstancioSource
tests (#1223)
wordTemplate()
spec that supports noun, verb, adjective, and adverb placeholders by @armandino in #1220- Bump com.fasterxml.jackson.core:jackson-databind from 2.18.1 to 2.18.2 by @dependabot in #1222
- Bump version.kotlin from 2.0.21 to 2.1.0 by @dependabot in #1221
- Bug fix: only report the initial seed for
@InstancioSource
tests by @armandino in #1223 - Throw an error by default if
applyFeed()
has unmapped feed properties by @armandino in #1225 - Bump org.apache.felix:maven-bundle-plugin from 5.1.9 to 6.0.0 by @dependabot in #1224
- Bump nl.jqno.equalsverifier:equalsverifier-nodep from 3.17.3 to 3.17.4 by @dependabot in #1227
- Bump com.puppycrawl.tools:checkstyle from 10.20.1 to 10.20.2 by @dependabot in #1226
Full Changelog: instancio-parent-5.1.0...instancio-parent-5.2.0
5.1.0
What's Changed
New Features
Add as(Function)
method to the oneOf()
generator spec (#1212)
Sample usage:
class Pojo {
JsonNullable<String> jsonNullableString;
}
Pojo pojo = Instancio.of(Pojo.class)
.generate(field("jsonNullableString"), gen -> gen.oneOf("foo", "bar").as(JsonNullable::of))
.create();
Related to:
Support for generating words (adjectives, adverbs, nouns, verbs) (#1213)
The word()
spec can generates words, including nouns, verbs, adjectives, and adverbs.
Example:
record Example(String word) {}
Example example = Instancio.of(Example.class)
.generate(field(Example::word), gen -> gen.text().word().noun())
.create();
// Sample output: Example[word=achievement]
Phrases or sentences can be constructed using a Supplier
:
record Company(String website) {}
Supplier<String> websiteSupplier = () -> String.format(
"https://www.%s-%s.com",
Instancio.gen().text().word().adjective().get(),
Instancio.gen().text().word().noun().get());
List<Company> companies = Instancio.ofList(Company.class)
.size(3)
.supply(field(Company::website), websiteSupplier)
.create();
// Sample output:
[[Company[website=https://www.global-bidder.com],
Company[website=https://www.independent-beat.com],
Company[website=https://www.promotional-clock.com]]
Bug Fixes
Apply scopes when converting root()
to all(Class)
for setModel()
(#1217)
- Bump org.junit:junit-bom from 5.11.2 to 5.11.3 by @dependabot in #1189
- Add
as(Function)
method to theoneOf()
generator spec by @armandino in #1212 - Support for generating words (adjectives, adverbs, nouns, verbs) by @armandino in #1213
- Minor refactor: clean up selector map by @armandino in #1214
- Bug fix: apply scopes when converting
root()
toall(Class)
forsetModel()
(#1215) by @armandino in #1217
Full Changelog: instancio-parent-5.0.2...instancio-parent-5.1.0
5.0.2
What's Changed
- Support for quoted CSV values in feeds by @berkayerten in #1142
- Bug fix: convert
root()
toall(Class)
selector when usingsetModel()
(#1159) by @armandino in #1160 - Dependency upgrades
New Contributors
- Thanks to @berkayerten for their first contribution! #1142
Full Changelog: instancio-parent-5.0.1...instancio-parent-5.0.2
5.0.1
What's Changed
- Bug fix: error applying feed specs to primitive fields by @armandino in #1125
Full Changelog: instancio-parent-5.0.0...instancio-parent-5.0.1
5.0.0
What's Changed
Breaking changes
Renamed classes:
org.instancio.InstancioOfClassApi
toInstancioClassApi
org.instancio.InstancioOfCollectionApi
toInstancioCollectionsApi
Breaking changes to experimental APIs
1. Removed the deprecated instancio-quickcheck
module
2. Replaced org.instancio.Gen
with org.instancio.Instancio.gen()
// Before
import org.instancio.Gen;
int n = Gen.ints().range(1, 10).get();
// Now
import static org.instancio.Instancio.gen;
int n = gen().ints().range(1, 10).get();
3. Removed method org.instancio.generator.ValueSpec.toModel()
:
Model<Integer> model = gen().ints().range(1, 10)
.toModel(); // toModel() method no longer available
The above can still be achieved using Instancio.of()
API:
Model<Integer> model = Instancio.of(Integer.class)
.generate(Select.root(), gen -> gen.ints().range(1, 10))
.toModel();
4. Renamed CartesianProductApi
class to InstancioCartesianProductApi
5. Renamed CsvGeneratorSpec.separator()
method to delimiter()
New Features
Feed
API for generating data from an external resource (CSV or JSON)
Example data file: persons.csv
firstName,lastName,age
John,Doe,21
Alice,Smith,34
# ...
List<Person> person = Instancio.ofList(Person.class)
.applyFeed(all(Person.class), feed -> feed.ofResource("persons.csv"))
.create();
// Output:
// [Person[firstName="John", lastName="Doe", age=21],
// Person[firstName="Alice", lastName="Smith", age=34],
// ...]
A feed can also be defined as an interface, which offers additional features and allows
the feed to be reused across multiple tests.
@Feed.Source(name = "persons.csv")
interface PersonFeed extends Feed {
FeedSpec<String> firstName(); // maps to 'firstName' property in the data file
@DataSpec("lastName") // maps to `lastName` property in the data file
FeedSpec<String> surname();
@TemplateSpec("${firstName} ${lastName}")
FeedSpec<String> fullName();
@FunctionSpec(params = "age", provider = DateOfBirthCalculator.class)
FeedSpec<LocalDate> dateOfBirth();
class DateOfBirthCalculator implements FunctionProvider {
LocalDate toDateOfBirth(int age) {
return LocalDate.now().minusYears(age);
}
}
}
// Sample usage
List<Person> person = Instancio.ofList(Person.class)
.applyFeed(all(Person.class), feed -> feed.of(PersonFeed.class))
.create();
// Output:
// [Person[firstName="John", surname="Doe", fullName="John Doe", age=21, ...],
// ...]
More info: https://www.instancio.org/user-guide/#data-feeds
@Given
annotation for injecting test fields and parameters
@ExtendWith(InstancioExtension.class)
class ExampleTest {
@Given
private String randomStringField;
@Test
void example1(@Given List<String> randomList) {
assertThat(randomStringField).isNotBlank();
assertThat(randomList).isNotEmpty();
}
@ValueSource(strings = {"foo", "bar"})
@ParameterizedTest
void example2(String fooOrBar, @Given long randomLong) {
assertThat(fooOrBar).isIn("foo", "bar");
assertThat(randomLong).isPositive();
}
}
The @Given
annotation can also be used with a custom GivenProvider
implementation, e.g.
@Given(CustomStringProvider.class)
private String customString;
Additionally, the @Given
annotation can be used to define custom annotations:
@Given(NumericStringProvider.class)
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@interface NumericString {
int length();
class NumericStringProvider implements GivenProvider {
@Override
public Object provide(ElementContext context) {
NumericString numericString = context.getAnnotation(NumericString.class);
return context.random().digits(numericString.length());
}
}
}
// Sample usage:
@ExtendWith(InstancioExtension.class)
class ExampleTest {
@Test
void example(@NumericString(length = 5) String digits) {
assertThat(digits).hasSize(5).containsOnlyDigits();
}
}
More info: https://www.instancio.org/user-guide/#given-injection
@InstancioSource
enhancements
- Added
samples
attribute - specifies the number of times a test method annotated with@InstancioSource
will run. - Added
Keys.INSTANCIO_SOURCE_SAMPLES
setting - configures the default number of samples.
By default, starting from version 5.0.0
, tests annotated with @InstancioSource
will run 100 times. This is a potentially breaking change, as previously, they were executed only once.
Example:
@ExtendWith(InstancioExtension.class)
class ExampleTest {
@ParameterizedTest
@InstancioSource
void example1(Foo foo) {
// will run 100 times with different instances of Foo
}
@ParameterizedTest
@InstancioSource(samples = 250)
void multipleArguments(Bar bar, Baz baz) {
// will run 250 times with different instances of Bar and Baz
}
}
Support for generating intervals of various types, such as numeric and temporal values
Example: generate a list of vacations with start/end dates.
record Vacation(LocalDate start, LocalDate end) {}
- The first vacation should start on
2000-01-01
. - Each vacation should last between 1-3 weeks.
- There should be 12-15 months between vacations.
IntervalSupplier<LocalDate> vacationDates = Instancio.gen()
.intervalStarting(LocalDate.of(2000, 1, 1))
.nextStart((end, random) -> end.plusMonths(random.intRange(12, 15)))
.nextEnd((start, random) -> start.plusWeeks(random.intRange(1, 3)))
.get();
List<Vacation> vacations = Instancio.ofList(Vacation.class)
.size(4)
.supply(field(Vacation::start), vacationDates.start())
.supply(field(Vacation::end), vacationDates.end())
.create();
// Sample output:
// [Vacation[start=2000-01-01, end=2000-01-15],
// Vacation[start=2001-02-15, end=2001-03-08],
// Vacation[start=2002-03-08, end=2002-03-15],
// Vacation[start=2003-06-15, end=2003-07-06]]
Support for assign().valueOf()
value with randomisation
Example: create a time period between 1 and 30 days, inclusive.
record TimePeriod(LocalDate start, LocalDate end) {}
TimePeriod period = Instancio.of(TimePeriod.class)
.assign(Assign.valueOf(TimePeriod::start)
.to(TimePeriod::end)
.as((LocalDate start, Random random) -> start.plusDays(random.intRange(1, 30))))
.create();
// Sample output: TimePeriod[start=2012-01-22, end=2012-01-30]
Support for Hibernate Validator constraints
- Brazil:
@CNPJ
,@CPF
@TituloEleitoral
(@brunodmartins) - Russia:
@INN
(@EvaristeGalois11)
New setting key: Keys.MAX_GENERATION_ATTEMPTS
Value spec for shuffling arrays and collections
- Removed deprecated
instancio-quickcheck
module by @armandino in #1063 - Breaking change: removed
ValueSpec.toModel()
method by @armandino in #1064 - Breaking changes: removed (experimental)
org.instancio.Gen
class by @armandino in #1065 - Minor refactoring of API interfaces by @armandino in #1066
- Support for assigning value with randomisation by @armandino in #1067
- Bump version.jooq from 3.19.9 to 3.19.10 by @dependabot in #1070
- Bump org.apache.maven.plugins:maven-jar-plugin from 3.4.1 to 3.4.2 by @dependabot in #1073
- Bump com.github.spotbugs:spotbugs-maven-plugin from 4.8.5.0 to 4.8.6.0 by @dependabot in #1076
- Bump org.apache.maven.plugins:maven-failsafe-plugin from 3.2.5 to 3.3.0 by @dependabot in #1071
- Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.5 to 3.3.0 by @dependabot in #1069
- Bump com.github.spotbugs:spotbugs-maven-plugin from 4.8.6.0 to 4.8.6.1 by @dependabot in #1081
- Bump org.projectlombok:lombok from 1.18.32 to 1.18.34 by @dependabot in #1080
- Bump org.junit:junit-bom from 5.10.2 to 5.10.3 by @dependabot in #1082
- Support for Hibernate Validator
@CPF
annotation (Brazil) #1006 by @brunodmartins in #1083 - Bump org.codehaus.mojo:versions-maven-plugin from 2.16.2 to 2.17.0 by @dependabot in #1084
- Brazil CNPJ generator by @brunodmartins in #1085
- Add INN Generator by @EvaristeGalois11 in #1086
- Fix timestamp generator test in CET timezone by @EvaristeGalois11 in #1087
- Bump org.codehaus.mojo:animal-sniffer-maven-plugin from 1.23 to 1.24 by @dependabot in #1089
- Remove asm dependency from animal sniffer plugin by @EvaristeGalois11 in #1090
- Update maven wrapper and switch to type only-script by @EvaristeGalois11 in #1091
- Brazil Titulo Eleitoral generator by @brunodmartins in #1092
- Bump com.github.spotbugs:spotbugs-maven-plu...