mercredi 29 juin 2016

junit test with dao create and get id

I have this service that I need to create Unit test for:

            SomeObject obj = new SomeObject();

            String objConfig = "<root id=%id% param1="something">....</root>"

            obj.setField1("value1");
            obj.setField2("value2");

            someObjectDao.create(obj);

            Long objId = obj.getId();
            obj.setConfig(objConfig.replace("%id%", objId.toString()));
            someObjectDao.update(obj);

Now, the problem is that in a real case, the DAO create will assign ID on the object, but how do I set the object ID through a Unit test?

Aucun commentaire:

Enregistrer un commentaire