sta-szek/pojo-tester

Issues with an enum with one value

junhoi-pk opened this issue · 1 comments

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.

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