Giter VIP home page Giter VIP logo

Comments (8)

seongahjo avatar seongahjo commented on September 25, 2024 1

@phuc16102001
In this case you could setup just as below.

private final FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
    .objectIntrospector(BuilderArbitraryIntrospector.INSTANCE)
    .pushExactTypeArbitraryIntrospector(B.class, (ctx) -> new ArbitraryIntrospectorResult(Arbitraries.just(null)))
    .defaultNotNull(true)
    .build();

@Test
void testCode() {
    B fieldB = new B("123");
    A createdObject = fixtureMonkey.giveMeBuilder(A.class)
	.set("fieldB", Values.just(fieldB)).sample();
    Assertions.assertNotNull(createdObject.getFieldB());
}

from fixture-monkey.

phuc16102001 avatar phuc16102001 commented on September 25, 2024 1

Oh thank you, it works now. πŸŽ‰

Ah also where I can find the latest document for the Fixture Monkey? Currently, it the 0.5.6 version has already available right? But the document still 0.5.0 which has some deprecated methods.

from fixture-monkey.

seongahjo avatar seongahjo commented on September 25, 2024 1

@phuc16102001

the 0.5.6 version has already available right?

Yes, 0.5.7 is the latest version.

where I can find the latest document for the Fixture Monkey

You'd better to check release
Document is now out-of-date since updating documentation has a lower priority.
I'll update the document as soon as possible.

from fixture-monkey.

phuc16102001 avatar phuc16102001 commented on September 25, 2024 1

Ok thank you very much.
I will close the issue then.
Once again, thank you! πŸ™‡

from fixture-monkey.

seongahjo avatar seongahjo commented on September 25, 2024

@phuc16102001
Hello, removeArbitray is not recommended in this situation.
removeArbitrary means remove the property fieldB, so set does not work as well.

In this situation, you'd better use pushExactTypeArbitraryIntrospector .
You have to find out which introspector would generate B.
B has @AllArgsConstructor, so ConstructorPropertiesArbitraryIntrospector would work if you have lombok.anyConstructor.addConstructorProperties=true in your lombok.config

private final FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
    .objectIntrospector(BuilderArbitraryIntrospector.INSTANCE)
    .pushExactTypeArbitraryIntrospector(B.class, ConstructorPropertiesArbitraryIntrospector.INSTANCE)
    .defaultNotNull(true)
    .build();

If not work, please let me know.
Thank you

from fixture-monkey.

phuc16102001 avatar phuc16102001 commented on September 25, 2024

But what if the B class does not have the @AllArgsConstructor too? Particularly, it is the GeoBoundingBox in Elastic Search. I have tried the ConstructorPropertiesArbitraryIntrospector but it throw this:

Primary Constructor does not exist. type GeoBoundingBox
java.lang.IllegalArgumentException: Primary Constructor does not exist. type GeoBoundingBox

Here is the constructor of the class:

public class GeoBoundingBox implements ToXContentObject, Writeable {

    private final GeoPoint topLeft;
    private final GeoPoint bottomRight;

    public GeoBoundingBox(GeoPoint topLeft, GeoPoint bottomRight) {
        this.topLeft = topLeft;
        this.bottomRight = bottomRight;
    }

    public GeoBoundingBox(StreamInput input) throws IOException {
        this.topLeft = input.readGeoPoint();
        this.bottomRight = input.readGeoPoint();
    }
}

from fixture-monkey.

phuc16102001 avatar phuc16102001 commented on September 25, 2024

Which version of Fixture Monkey are you using? Because I cannot find the setJust method.

from fixture-monkey.

seongahjo avatar seongahjo commented on September 25, 2024

@phuc16102001
Oh, sorry, you could use set instead of setJust

from fixture-monkey.

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.