TracingDataSource implements DataSource { public static DataSource wrapWithTracingIfEnabled(DataSource dataSource) { return Boolean.valueOf(System.getenv("CHE_DB_TRACING_ENABLED")) ? new TracingDataSource(dataSource) : dataSource; } 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 shouldBeAbleTogetTracingDataSource() throws Exception { setEnv(ImmutableMap.of("CHE_DB_TRACING_ENABLED", "true")); DataSource actual = TracingDataSource.wrapWithTracingIfEnabled(dataSource); assertEquals(actual.getClass(), TracingDataSource.class); }
@Test public void shouldNotWrapDatasourceIfEnvSetToFalseØ() throws Exception { setEnv(ImmutableMap.of("CHE_DB_TRACING_ENABLED", "false")); DataSource actual = TracingDataSource.wrapWithTracingIfEnabled(dataSource); assertEquals(actual, dataSource); }
@Test public void shouldNotWrapDatasourceIfEnvIsNotSet() throws Exception { DataSource actual = TracingDataSource.wrapWithTracingIfEnabled(dataSource); assertEquals(actual, dataSource); }