title: How to mockup an entityManager for unit testing a service
body: <p>I´m trying to write some unit tests for my company, so its not possible for me to change anything in sourceCode but everything in the tests.
  I´m using Java8, Spring, Mockito and JUnit4.</p>
  
  <p>Problem: There are some services with a entityManager, which gets instantiated via dependencyInjection</p>
  
  <pre><code>@PersistenceContext(unitName = someName)
  private EntityManager em;
  </code></pre>
  
  <p>I tried to mock this and injecting it into my ClassUnderTest, like i mocked every other class but that doesn´t work.</p>
  
  <pre><code>@InjectMocks
  @Autowired
  private SomeService testedSomeService;
  </code></pre>
  
  <p>There´s always an "IllegalStateException: Failed to load application context" before running the first test, with a hint to the entity manager. 
  If i make the annotation to a comment, every method gets tested fine (except the methods, using entityManager).</p>
  
  <p>Is there a simple way to mock the entityManager? or how can i inject a dependency in my testclass? </p>
  
  <p>I appreciate ANY help!</p>