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

Issues with an enum with one value #199

Closed
junhoi-pk opened this issue Jul 18, 2017 · 1 comment
Closed

Issues with an enum with one value #199

junhoi-pk opened this issue Jul 18, 2017 · 1 comment
Labels
Milestone

Comments

@junhoi-pk
Copy link

The following test code throws an IllegalArgumentException.

@Test
public void test() throws Exception {
    assertPojoMethodsFor(TestClass.class).areWellImplemented();
}

@Data
class TestClass {
    E e;
}

enum E {
    A;
}

However, the code below succeeds.

@Test
public void test() throws Exception {
    assertPojoMethodsFor(TestClass.class).areWellImplemented();
}

@Data
class TestClass {
    E e;
}

enum E {
    A,
    B;
}

The error is the code below (pl.pojo.tester.internal.instantiator.EnumInstantiator)

public Object instantiate() {
    Object[] enumConstants = this.clazz.getEnumConstants();
    int length = enumConstants.length;
    if(length != 0) {
        int random = (new Random()).nextInt(length - 1);
        return enumConstants[random];
    } else {
        return null;
    }
}

Occurs when the length is 1.

@sta-szek
Copy link
Owner

Thanks for reporting,
It seems to be very easy to implement this, @JunGrammer would you like to try?

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

No branches or pull requests

2 participants