Skip to content
Advertisement

Error java.lang.AssertionError: expected: null but was: java.lang.String what does it mean?

I have this strange issue in my Junit 4.12 test code. The application uses Spring Framework 4.1.6 and Hibernate 4. When comparing two beans coming from different databases I get this error

JavaScript

What does it mean? How to resolve it?

My test class runs with SpringJUnit4ClassRunner and looks similar to this

JavaScript

edit: the bean I’m referring to is a simple POJO, you can imagine it look like the following:

JavaScript

I get them using Hibernate along the line of

JavaScript

To address the close vote: I’m not sure if all these details may help, the question is about the strange AssertError I get rather than how I get the beans. I can’t find help here in SO nor Google.

edit2: to further clarify, the POJO itself is the exact same Java class, I use two hibernate mappings files. The only difference is catalog="this" and catalog="that" in the mapping. I use two different sessionfactories because data is stored in different schemas (aka catalog), same MySQL instance.

Advertisement

Answer

After some more digging I’ve discovered that the beans are not identical. The regular DAO sets the string with value null on Thing, while test data DAO sets null on Thing. The failing assert is

JavaScript

I’m happy that it fails, values are different. The detail message is quite cryptical though.

Advertisement