mtedone / podam

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

PODAM fails to initialize MyType<T> containing final Map<T,T> #247

Closed JordanAngold closed 6 years ago

JordanAngold commented 7 years ago

I have a test case that requires PODAM to create and fill a POJO containing a final Map<T,T> as suggested in the title, and found that it doesn't work. I'm using PODAM 7.0.5 .

I have distilled the problem down to this example:

public class MyTest {
    @Test
    public void test() {
        PodamFactory factory = new PodamFactoryImpl();
        MyType<String> wrapper = factory.manufacturePojoWithFullData(MyType.class, String.class);
        assertNotNull(wrapper);
    }

    public static class MyType<T> {
        /* // works:
        Map<T,T> map;
        public void setMap(Map<T,T> map) { this.map = map; }
        //*/

        // doesn't work:
        final Map<T,T> map = new HashMap<>();

        public Map<T,T> getMap() {
            return map;
        }
    }
}

If you use the 'doesn't work' part, you get:

java.lang.IllegalArgumentException: java.util.Map is missing generic type arguments, expected [K, V], provided [T, T]
    at uk.co.jemos.podam.typeManufacturers.TypeManufacturerUtil.fillTypeArgMap(TypeManufacturerUtil.java:169)
    at uk.co.jemos.podam.api.PodamFactoryImpl.populateReadOnlyField(PodamFactoryImpl.java:709)
    at uk.co.jemos.podam.api.PodamFactoryImpl.populatePojoInternal(PodamFactoryImpl.java:622)
    at uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojoInternal(PodamFactoryImpl.java:533)
    at uk.co.jemos.podam.api.PodamFactoryImpl.doManufacturePojo(PodamFactoryImpl.java:436)
    at uk.co.jemos.podam.api.PodamFactoryImpl.manufacturePojoWithFullData(PodamFactoryImpl.java:141)
    at MyTest.test:15

If you instead use the 'works' part instead, then you get a correctly-constructed object.

daivanov commented 7 years ago

Please, try 7.1.1 snapshot: https://oss.sonatype.org/content/repositories/snapshots/uk/co/jemos/podam/podam/7.1.1-SNAPSHOT/

JordanAngold commented 7 years ago

Thank you for your swift response. I spent some time testing 7.1.1 and it seems to have fixed the issue I described above.

Unfortunately, the test I am working with is brittle and breaks for a number of other reasons with 7.1.1 (as compared to 7.0.5). I haven't been able to do a full analysis of the cause, but it could be anything between those versions -- I have no particular reason to believe that it's 7.1.1 itself.

I don't know when I will get more time to deal with those issues (it certainly won't be for at least a week). I think this ticket can probably be closed, but I will leave that decision up to you.

daivanov commented 7 years ago

There is also version 7.1.0, which was released some time ago. You can enable debug log level and this should give you a good hint what is happening in your tests and what could be a root cause for a problems.

daivanov commented 6 years ago

Let's close this issue. Fixed in Podam 7.1.1 or later.