8000 Releases Β· instancio/instancio Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Releases: instancio/instancio

5.4.1

21 Mar 04:53
Compare
Choose a tag to compare

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

Full Changelog: instancio-parent-5.4.0...instancio-parent-5.4.1

5.4.0

22 Feb 05:01
Compare
Choose a tag to compare

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

21 Jan 07:51
Compare
Choose a tag to compare

What's Changed

New Features

  • New top-level APIs Instancio.fill(T) and Instancio.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)

Full Changelog: instancio-parent-5.2.1...instancio-parent-5.3.0

5.2.1

11 Dec 04:47
Compare
Choose a tag to compare
8000

What's Changed

Bug Fixes

Generating numbers based on bean validation constraints (#1240)


Full Changelog: instancio-parent-5.2.0...instancio-parent-5.2.1

5.2.0

02 Dec 23:11
Compare
Choose a tag to compare

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

25 Nov 02:39
Compare
Choose a tag to compare

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)


Full Changelog: instancio-parent-5.0.2...instancio-parent-5.1.0

5.0.2

12 Sep 17:26
Compare
Choose a tag to compare

What's Changed

  • Support for quoted CSV values in feeds by @berkayerten in #1142
  • Bug fix: convert root() to all(Class) selector when using setModel() (#1159) by @armandino in #1160
  • Dependency upgrades

New Contributors

Full Changelog: instancio-parent-5.0.1...instancio-parent-5.0.2

5.0.1

28 Jul 19:55
Compare
Choose a tag to compare
10000 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

23 Jul 23:35
Compare
Choose a tag to compare

What's Changed

Breaking changes

Renamed classes:

  • org.instancio.InstancioOfClassApi to InstancioClassApi
  • org.instancio.InstancioOfCollectionApi to InstancioCollectionsApi

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

New setting key: Keys.MAX_GENERATION_ATTEMPTS

Value spec for shuffling arrays and collections


Read more

4.8.1

26 Jun 02:25
Compare
Choose a tag to compare

What's Changed

Bug fix

  • Bug fix: error generating ZoneId on Java 17+ (#1077)
0