mtedone / podam

PODAM - POjo DAta Mocker
https://mtedone.github.io/podam
MIT License
323 stars 750 forks source link

boolean fields starting with "is" are never filled #290

Closed vincent-petit closed 2 years ago

vincent-petit commented 3 years ago

boolean fields starting with "is" are never set by podam, using lombok for getter/setter.

How to reproduce:

// Using lombok, the method signature for getter and setter are:
// * isCondition1() / isCondition2() 
// * setCondition1(boolean condition) / setCondition2(boolean condition)
@lombok.Data
class ClassWithBoolean {
  boolean condition1;
  boolean isCondition2;
}
ClassWithBoolean expected = new ClassWithBoolean();
expected.setCondition1(true);
expected.setCondition2(true);
// The below assert failed, the field isCondition2 is always false
Assertions.assertThat(new PodamFactoryImpl().manufacturePojo(ClassWithBoolean.class))
      .isEqualTo(expected);

Versions: Podam:7.2.6 Lombok:1.18.20 / https://projectlombok.org/features/GetterSetter

daivanov commented 3 years ago

Hi,

Yes, this is because such naming is non-standard for Java Beans. To make it work you should implement your own ClassInfoStrategy, which will be picking up non-standard properties. One way of doing this is to subclass AbstractClassInfoStrategy. Then just set this ClassInfoStrategy to the PodamFactory https://mtedone.github.io/podam/apidocs/uk/co/jemos/podam/api/PodamFactory.html#setClassStrategy-uk.co.jemos.podam.api.ClassInfoStrategy-

Thanks, Daniil