Giter Site home page Giter Site logo

Comments (2)

nomemory avatar nomemory commented on May 22, 2024

@pricelessspirit

Support for non-static inner classes reflection can be a little bit tricky to implement at the level of reflection (because of how the library is done - i need a reference to the outer class but i don't have that since everything is created lazy...).

I will think of a solution for that, but until then I recommend you to use the filler() method that instead of using reflection is using a Supplier<T>.

The code using filler should be like this:

List<Patient> patientList = mockNeat.filler(() -> {
                                        Patient p = new Patient();
                                        p.setdOB(
                                            m.filler(() -> p.new DOB())
                                             .setter(Patient.DOB::setEstimated, m.bools())
                                             .setter(Patient.DOB::setPremature, m.bools())
                                             .val()
                                        );
                                        return p;
                                    })
                                   .setter(Patient::setFirstName, m.names().first())
                                   .setter(Patient::setLastName, m.names().last())
                                   .list(() -> new ArrayList<>(), 10)
                                   .val();

System.out.println(patientList);

Or if you want to de-couple the DOB creation from the Patient class:

Function<Patient, Patient> dobPopulator =
                (patient) -> {
                    Patient.DOB dob = m.filler(() -> patient.new DOB())
                                       .setter(Patient.DOB::setPremature, mockNeat.bools())
                                       .setter(Patient.DOB::setEstimated, mockNeat.bools())
                                       .val();
                    patient.setdOB(dob);
                    return patient;
                };


List<Patient> patientList = mockNeat.filler(() -> new Patient())
                                   .setter(Patient::setFirstName, m.names().first())
                                   .setter(Patient::setLastName, m.names().last())
                                   .map(dobPopulator)
                                   .list(() -> new ArrayList<>(), 10)
                                   .val();

System.out.println(patientList);

from mockneat.

pricelessspirit avatar pricelessspirit commented on May 22, 2024

For now, I will try to take out sub classes into the own classes, and their packages. I don't want to deal with getters and setters. Sub-classes, we were good for me because I could place class definitions for small types under a main object class definition. For now, I will try to organize into separate data packages and use mockneat for generating data. By the way, big thanks for your suggestions.

from mockneat.

Related Issues (20)

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.