openpojo
openpojo copied to clipboard
In openpojo how can I ignore the type of list whether arraylist or collection?
I'm using openpojo
library having version 0.8.10
. There is a scenario where I've following class:
public class Foo {
//few variables & objects
List<Bar> bars;
//all objects/variables & lists are constructed through constructor
public Foo(...,...,List<Bar> bars){
this.bars =bars;
}
//no setters
//getters are there
public Collection<Bar> getBars(){
return null != bars ? Collection.unmodifiableCollection(bars) : null;
}
}
In one of the test class, it has getter & setter validation using openpojo is as follow:
import com.openpojo.reflection.impl.PojoClassFactory;
import com.openpojo.validation.Validator;
import com.openpojo.validation.ValidatorBuilder;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
@ExtendWith(SpringExtension.class)
public class FooTest{
@FooTest
public void testGettersAndSetters(){
PojoClass pojo = PojoClassFactory.getPojoClass(Foo.class);
Validator Validator = ValidatorBuilder.create()
.with(new SetterTesters())
.with(new GetterTesters())
.build();
Validator.validate(pojo);
}
}
After running the above test, I'm getting the following exception:
java.lang.AssertionError: Getter returned non equal value for field
Expected: java.util.ArrayList<[Bar{....}
Actual: java.util.Collections$UnmodifiableCollection<[Bar{....
The Bar class gonna remain the same, what changes I could do in test classes so that I can match the ArrayList
with Collections.unmodifiableCollection
?
I've raised same on StackOverflow as well: https://stackoverflow.com/questions/70953219/in-openpojo-how-can-i-ignore-the-type-of-list-whether-arraylist-or-collection