In my project I use XStream to serialize/deserialize my entities.
Everythings works fine in the application but not when I trie to create some unit tests.
I have an abstract class A
with a field name
and public accessors. I have a class B
that extends A
.
My XStream configuration is like this one:
XStream xStream = new XStream();
//
xStream.alias("classNameSerialized", AnotherClass.class);
xStream.aliasAttribute(AnotherClass.class, OBJECT_ATTRIBUT_VERSION, OBJECT_ATTRIBUT_VERSION);
...
//
xStream.alias("classNameSerialized", B.class);
xStream.aliasAttribute(B.class, "name", "name");
When I run my application, there is no problem. But when I try to create an unit test, XStream fires the exception: IllegalArgumentException: could not access org.mycompagny.B.name field: name
EDIT
I tried in my test B.class.getDeclaredField("name");
and it throws me the same exception. But when I try A.class.getDeclaredField("name");
there is no problem. I understand that it can be a problem whith the reflection, but what I cannot understand is why this problem appears just in my unit test and not in my application...
The final question is how can I test this code???
Aucun commentaire:
Enregistrer un commentaire