GithubHelp home page GithubHelp logo

dvgaba / easy-random Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 4.0 3.33 MB

The simple, stupid random Java beans/records generator

Home Page: https://github.com/j-easy/easy-random/wiki

License: MIT License

Java 100.00%
java protobuf testing java-random jdk16 java-records junit random-data-generation

easy-random's People

Contributors

arnzel avatar carborgar avatar dadiyang avatar dvgaba avatar dziga avatar feckertson avatar fmbenhassine avatar frankowskid avatar georgekankava avatar gitter-badger avatar huningd avatar jin-harmoney avatar kermit-the-frog avatar lejeanbono avatar lucasandersson avatar lutovich avatar mjureczko avatar pascalschumacher avatar petromir avatar prietopa avatar reitzmichnicht avatar rmcquary avatar rodriguealcazar avatar sansherbina avatar seregamorph avatar svcacct-epo-cicd avatar toilal avatar unconditional avatar valters avatar xcorail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

easy-random's Issues

Copyright infringement: Please remove easy-random-protobuf

Randomization parameters are not used for records

When trying to generate random record, it seems that EasyRandomParameters are not used for generation.
Example:

import org.jeasy.random.EasyRandom;
import org.jeasy.random.EasyRandomParameters;
import org.jeasy.random.randomizers.text.StringRandomizer;
import org.junit.jupiter.api.Test;

import static org.jeasy.random.FieldPredicates.named;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestParameters {

    private final EasyRandom easyRandom = new EasyRandom(new EasyRandomParameters()
        .randomize(named("name"), new StringRandomizer(1))
    );

    @Test
    void test() {
        var result = easyRandom.nextObject(TestRecord.class);
        assertEquals(1, result.name().length());
    }

    record TestRecord(
        String name,
        String phone
    ){}
}

Result:

Expected :1
Actual   :23

easyRandom.objects always returning the same record list

Hi,

Just found a bug regarding records. When you randomize a list of records, it's always returning the same value, so all the objects inside the stream are the same (see attached test). I opened the issue just in case someone is facing the same and can provide a workaround or guidelines to fix it.

This is the test I made:

    @Test
    void typeRecordListShouldBePopulatedWithDifferentValues() {
        List<TestRecord> recordList = easyRandom.objects(TestRecord.class, 2).toList();

        TestRecord rnd1 = recordList.get(0);
        TestRecord rnd2 = recordList.get(1);

        assertThat(rnd1).isNotEqualTo(rnd2);

    }

Found it using version 6.1.7

Record fields still being generated even if randomizer is specified for field to set it to null

Given a record like:

public record MyRecord(String fieldOne, AnotherRecord fieldTwo) {}

where AnotherRecord is a record

When I do:

easyRandomParameters.randomize(
            field -> field.equals(fieldTwoField), () -> null
        );

I would expect the value for fieldTwo to be null. This works with most primitives & other classes that are not records. However, with records, fieldTwo is not null and still subject to value generation.

I've sort of worked around this by also adding:

easyRandomParameters.randomize(AnotherRecord.class, new SkipRandomizer());

however if in my object I have more than one field that is AnotherRecord, ie:

public record SomeOtherRecord(AnotherRecord fieldOne, AnotherRecord fieldTwo) {}

naturally both fieldOne & fieldTwo would be skipped, so it doesn't work in those scenarios. The intention is just to null out that single field (fieldTwo).

Better jitpack.io support

jitpack runs your build with Java 8

Easy fix

jitpack.yml

jdk:
  - openjdk17
install:
  - mvn install -Dmaven.javadoc.skip=true -DskipTests

[Feature] New module to support generate salesforce entities generation

Thank you for taking time to open this issue! Please check the known limitations section before opening an issue.

Please provide as much context as possible to help us fixing the issue (at least easy-random version you are using).

  • If you are reporting a bug, the best way is to provide a failing test.
  • If you are requesting a feature, don't hesitate to explain in detail your suggestion with code examples.
  • If you have a question, please first check if there is no (closed) issue about it. You may ask your question on the Gitter channel of the project.

Many thanks upfront!

Protobuf randomizer not using custom randomizers

hi,
I just noticed that protobuf field predicates are not working when specifying custom random values providers.

For example, the following test fails

    void shouldUseCustomProviderRegistryToFillFields(){
        EasyRandomParameters parameters = new EasyRandomParameters().randomize(ProtobufPredicates.named("int32Field"), () -> 42);
        EasyRandom easyRandom = new EasyRandom(parameters);

        Proto3Message protoInstance = easyRandom.nextObject(Proto3Message.class);

        assertThat(protoInstance.getInt32Field()).isEqualTo(42);
    }

I've found a solution and pushed it to my fork, will create PR now because it involves exposing EasyRandomParameters's custom randomizer provider so that we are able to access it. Any suggestion is welcome.

Version 6.1.8 does not initialize collections at the end of nesting data structures

There is a test that is supposed to verify the scenario, i.e. shouldLimitTheNestingLevel_whenInRecursiveStructures, but it was changed from:

        assertThat(actual.children().get(0))
            .as("On the 2nd level, the field should be initialized with empty list, i.e. end of nesting.")
            .isEqualTo(new NestedRecordThroughCollection(List.of()));

to:

        assertThat(actual.children().get(0))
            .as("On the 2nd level, the field should be initialized with empty list, i.e. end of nesting.")
            .isEqualTo(new NestedRecordThroughCollection(null));

When reverting the test, it fails as the list 'in children' is not initialized.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.