title: Junit Testing: Failed to test TransactionStatus
body: <p>Am new to Junit Testing..I have a scenario ,</p>
  
  <pre><code>@Service
  public class MainWorkerClass {
  
      @Autowired
      @Qualifier("txnManager")
      private HibernateTransactionManager txnManager;
  
      public void task() {
      .....
      TransactionStatus txnStatus = txnManager.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW));
      .....
      }
  
  }
  </code></pre>
  
  <p>My junit class failing at, getTransaction() where logger.isDebugEnabled() throws NPE.
  So I did alternate like below,</p>
  
  <pre><code>public class JnuitTestTxnMgr  implements PlatformTransactionManager{
      @Override
      public void commit(TransactionStatus arg0) throws TransactionException {}
      @Override
      public TransactionStatus getTransaction(TransactionDefinition arg0) throws TransactionException {
      return null;
      }
      @Override
      public void rollback(TransactionStatus arg0) throws TransactionException {}
  
  }
  </code></pre>
  
  <p>and my junit class is like,</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = {DBConfig.class})
  public class MainWorkerClassTest {
      @Mock
      JnuitTestTxnMgr jnuitTransactionManagerOTP = new JnuitTestTxnMgr();
      @InjectMocks
      MainWorkerClass worker = new MainWorkerClass();
      @Test
      public void testTask() throws Exception{
      worker.task();
      }
  </code></pre>
  
  <p>But fortunately, injected mock object is of type JnuitTestTxnMgr and the class to be tested has HibernateTransactionManager which is not accepted one.
  Is there any workaround for my alternative solution or any solution there to test my original class.</p>
  
  <p>Note I cannot change my jars, am using spring4 &amp; hibernate4</p>