Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Excluding classes from generation #1016

Open
lfcazambuja opened this issue Jul 28, 2024 · 1 comment
Open

Issue Excluding classes from generation #1016

lfcazambuja opened this issue Jul 28, 2024 · 1 comment
Labels
question Further information is requested

Comments

@lfcazambuja
Copy link

lfcazambuja commented Jul 28, 2024

Hi!

I'm using Fixture Monkey version 1.0.4. I updated it to the latest version, but some of my unit tests started to fail.

Basically I have a class excluded from generation, like the example shown here.

The problem is that I want to exclude the field from generation, but I need to manually set the respective field in one specific situation. And it was working until the version 1.0.9. After this version, the behavior was modified, and it'snot working anymore.

Taking the example of the link:

@Test
void testExcludeClass() {
    FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
        .addExceptGenerateClass(String.class)
        .build();

    String actual = sut.giveMeOne(Product.class)
      .getProductName();

    then(actual).isNull();
}

the test will fail if I change it to

@Test
void testExcludeClass() {
    FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
                .objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
                .addExceptGenerateClasses(String.class)
                .defaultNotNull(true)
                .build();

    String product = fixtureMonkey.giveMeBuilder(Product.class)
      .set("productName", "some-name")
      .sample();

    then(product.getProductName()).isEqualTo("some-name");
}

product.getProductName() is null in this scenario.

It's ok for me having the field with null value if I don't explicitly set it. But I want the possibility to set it with a given value, which is not allowed anymore.

Please bear in mind that I've excluded a String field just to follow the given example. In my scenario I have a complex type instead of a String.

My question is: is that a bug or a feature?

Thanks in advance.

@lfcazambuja lfcazambuja added the question Further information is requested label Jul 28, 2024
@seongahjo
Copy link
Contributor

seongahjo commented Jul 29, 2024

@lfcazambuja
Hello.

My question is: is that a bug or a feature?

It is a feature. You can find out the following PR in here

In your situation, I recommend that you use Just. It forces the value to be set.

@Test
void testExcludeClass() {
    FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
                .objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
                .addExceptGenerateClasses(String.class)
                .defaultNotNull(true)
                .build();

    Product product = fixtureMonkey.giveMeBuilder(Product.class)
      .set("productName", Values.just("some-name"))
      .sample();

    then(product.getProductName()).isEqualTo("some-name");
}

Let me know if you have any further problems.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants