title: Integration test a manual transaction with transaction template
body: <p>I am getting null pointer exceptions on my transaction template when I try to test my method that uses manual transactions. When I am running the application in Spring Boot it works as expected.</p>
  
  <pre><code>@Autowired
  TransactionTemplate template;
  
  public CompletableFuture&lt;MyResultEntity&gt; addToA(BInput input) {
      return CompletableFuture
          .supplyAsync(
              () -&gt; template.execute(status -&gt; {
                A a = aRepository.findOne(input.getA());
                List&lt;B&gt; addedBs = saveBs(input.getB(), a);
                return new MyResultEntity(a, addedBs);
              }), MyCustomExecutor());
  }
  </code></pre>
  
  <p>I have tried using a mock template and inject it like this:</p>
  
  <pre><code>@Mock
  private TransactionTemplate transactionTemplate;
  
  @InjectMocks
  private MyClass myClass;
  </code></pre>
  
  <p>I have also tried annotating my test with:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  </code></pre>
  
  <p>When debugging this configuration the template is actually injected and is not null any more. But since I am interested in testing the actions in the transactions I do not wish to mock it so i use:</p>
  
  <pre><code>when(transactionTemplate.execute(Mockito.any())).thenCallRealMethod();
  </code></pre>
  
  <p>This throws a new null pointer exception though since the transaction template tries to use the TransactionManager and that is still null.</p>
  
  <p>How can I unit test my method calls inside the the transaction template?</p>