Usually in unit testing, mocking of objects is used; but how should one write unit tests for a JPA Entity for example if the EntityManager is mocked? What is actually tested?
Edit: Suppose I want to test if an object is well persisted; in production code, for persistence, a container-provided EntityManager is available. For this type of tests should this EntityManager be mocked, should it be a resource-local one for tests or should the tests be ran in the container (test running be triggered from Java code)?
An entity represents data. It can have some methods (other than getters and setters) that can be unit-tested as any other method.
If you want to test that the entity can be persisted and retrieved from the database (i.e. that its mapping is defined correctly), then you shouldn’t mock anything. Have a test that uses a real entity manager and a database filled with test data, and that tries to persist and/or retrieve an instance of your entity.
You could use DbSetup (yes, self-promotion here) to fill the database with test data before such tests.