TracingDataSource implements DataSource { @Override public Connection getConnection() throws SQLException { return new TracingConnection( delegate.getConnection(), connectionInfo, true, null, GlobalTracer.get()); } TracingDataSource(DataSource delegate); @Override Connection getConnection(); @Override Connection getConnection(String username, String password); @Override T unwrap(Class<T> iface); @Override boolean isWrapperFor(Class<?> iface); @Override PrintWriter getLogWriter(); @Override void setLogWriter(PrintWriter out); @Override void setLoginTimeout(int seconds); @Override int getLoginTimeout(); @Override Logger getParentLogger(); static DataSource wrapWithTracingIfEnabled(DataSource dataSource);  }
@Test public void shouldBeAbleToGetConnection() throws SQLException { TracingDataSource ds = new TracingDataSource(dataSource); Connection actual = ds.getConnection(); assertEquals(actual.getClass(), TracingConnection.class); Mockito.verify(dataSource, Mockito.times(2)).getConnection(); }
@Test public void shouldBeAbleToGetConnectionWithEmailAndPassword() throws SQLException { TracingDataSource ds = new TracingDataSource(dataSource); Connection actual = ds.getConnection("user", "password"); assertEquals(actual.getClass(), TracingConnection.class); Mockito.verify(dataSource).getConnection(Mockito.eq("user"), Mockito.eq("password")); }