Tracer { public static Transaction newTransaction(String type, String name) { try { return getProducer().newTransaction(type, name); } catch (Throwable ex) { logger.warn("Failed to create transaction for type: {}, name: {}", type, name, ex); return NULL_MESSAGE_PRODUCER_MANAGER.getProducer().newTransaction(type, name); } }  static void logError(String message, Throwable cause); static void logError(Throwable cause); static void logEvent(String type, String name); static void logEvent(String type, String name, String status, String nameValuePairs); static Transaction newTransaction(String type, String name);  }
@Test public void testNewTransaction() throws Exception { String someType = "someType"; String someName = "someName"; Transaction someTransaction = mock(Transaction.class); when(someProducer.newTransaction(someType, someName)).thenReturn(someTransaction); Transaction result = Tracer.newTransaction(someType, someName); verify(someProducer, times(1)).newTransaction(someType, someName); assertEquals(someTransaction, result); }
@Test public void testNewTransactionWithException() throws Exception { String someType = "someType"; String someName = "someName"; when(someProducer.newTransaction(someType, someName)).thenThrow(RuntimeException.class); Transaction result = Tracer.newTransaction(someType, someName); verify(someProducer, times(1)).newTransaction(someType, someName); assertTrue(result instanceof NullTransaction); }