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

In openpojo how can I ignore the type of list whether arraylist or collection? #143

Open
iAshwinK opened this issue Feb 2, 2022 · 0 comments

Comments

@iAshwinK
Copy link

iAshwinK commented Feb 2, 2022

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

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

No branches or pull requests

1 participant