### Question:
JtaTransactionManager implements TransactionManager { @Override public Transaction startTransaction() { if (isTransactionynchronizationRegistryAvailable()) { return ParticipatingRegisteredTransaction.usingRegistry(transactionRegistry); } if (isUserTransactionAvailable()) { if (isInTransaction()) { return ParticipatingUserTransaction.usingUserTransaction(userTransaction); } return LeadingUserTransaction.usingUserTransaction(userTransaction); } return NoTransaction.INSTANCE; } protected  JtaTransactionManager(UserTransaction userTransaction,
			TransactionSynchronizationRegistry transactionRegistry); static final TransactionManager using(UserTransaction user, TransactionSynchronizationRegistry registry); @Override Transaction startTransaction(); @Override String toString();  }### Answer:
@Test public void useParticipatingRegisteredTransactionIfAvailable() { setField("userTransaction", null); Transaction transaction = transactionManager.startTransaction(); assertThat(transaction, CoreMatchers.instanceOf(ParticipatingRegisteredTransaction.class)); }
@Test public void otherwiseUseParticipatingUserTransactionIfAvailable() throws SystemException { setField("transactionRegistry", null); when(userTransaction.getStatus()).thenReturn(Status.STATUS_PREPARED); Transaction transaction = transactionManager.startTransaction(); assertThat(transaction, CoreMatchers.instanceOf(ParticipatingUserTransaction.class)); }
@Test public void useLeadingUserTransactionIfNoUserTransactionIsRunningYet() throws SystemException { setField("transactionRegistry", null); when(userTransaction.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION); Transaction transaction = transactionManager.startTransaction(); assertThat(transaction, CoreMatchers.instanceOf(LeadingUserTransaction.class)); }
@Test public void useLeadingUserTransactionIfUserTransactionStatusQueryFails() throws SystemException { setField("transactionRegistry", null); when(userTransaction.getStatus()).thenThrow(new SystemException("Test")); Transaction transaction = transactionManager.startTransaction(); assertThat(transaction, CoreMatchers.instanceOf(LeadingUserTransaction.class)); }
@Test public void noTransactionIfThereIsNoWayToObtainOne() { setField("userTransaction", null); setField("transactionRegistry", null); Transaction transaction = transactionManager.startTransaction(); assertThat(transaction, equalTo(NoTransaction.INSTANCE)); }