DataSource { private static void debug(String sql, @Nullable Object... args) { debug(logger, sql, args); } DataSource();  DataSource(File dbFile); void defrag(); void compact(); long getH2DataFileSize(); List<H2Table> analyzeH2DiskSpace(); void deleteAll(); void execute(@Untainted String sql); long queryForLong(final @Untainted String sql, Object... args); @Nullable Long queryForOptionalLong(final @Untainted String sql, Object... args); List<String> queryForStringList(final @Untainted String sql); T query(JdbcQuery<T> jdbcQuery); T queryAtMostOne(JdbcRowQuery<T> jdbcQuery); List<T> query(JdbcRowQuery<T> jdbcQuery); int update(final @Untainted String sql, final @Nullable Object... args); int update(JdbcUpdate jdbcUpdate); int[] batchUpdate(JdbcUpdate jdbcUpdate); void deleteBefore(@Untainted String tableName, long captureTime); void deleteBefore(@Untainted String tableName, @Untainted String columnName,
            long captureTime); void deleteBeforeUsingLock(@Untainted String tableName, @Untainted String columnName,
            long captureTime, Object externalLock); void syncTable(@Untainted String tableName, List<Column> columns); void syncIndexes(@Untainted String tableName, ImmutableList<Index> indexes); boolean tableExists(String tableName); boolean columnExists(String tableName, String columnName); void renameTable(@Untainted String oldTableName, @Untainted String newTableName); void renameColumn(@Untainted String tableName, @Untainted String oldColumnName,
            @Untainted String newColumnName); V suppressQueryTimeout(Callable<V> callable); @OnlyUsedByTests void close();  }
@Test public void testDebugNoArgs() throws SQLException { Logger logger = mock(Logger.class); when(logger.isDebugEnabled()).thenReturn(true); DataSource.debug(logger, "select x from y"); verify(logger).isDebugEnabled(); verify(logger).debug("select x from y"); verifyNoMoreInteractions(logger); }
@Test public void testDebugOneStringArg() throws SQLException { Logger logger = mock(Logger.class); when(logger.isDebugEnabled()).thenReturn(true); DataSource.debug(logger, "select x from y where a = ?", "aaa"); verify(logger, times(2)).isDebugEnabled(); verify(logger).debug("{} [{}]", "select x from y where a = ?", "'aaa'"); verifyNoMoreInteractions(logger); }
@Test public void testDebugOneNullArg() throws SQLException { Logger logger = mock(Logger.class); when(logger.isDebugEnabled()).thenReturn(true); DataSource.debug(logger, "select x from y where a = ?", new Object[] {null}); verify(logger, times(2)).isDebugEnabled(); verify(logger).debug("{} [{}]", "select x from y where a = ?", "NULL"); verifyNoMoreInteractions(logger); }
@Test public void testDebugOneNumberArg() throws SQLException { Logger logger = mock(Logger.class); when(logger.isDebugEnabled()).thenReturn(true); DataSource.debug(logger, "select x from y where a = ?", 99); verify(logger, times(2)).isDebugEnabled(); verify(logger).debug("{} [{}]", "select x from y where a = ?", "99"); verifyNoMoreInteractions(logger); }
@Test public void testDebugMultipleArgs() throws SQLException { Logger logger = mock(Logger.class); when(logger.isDebugEnabled()).thenReturn(true); DataSource.debug(logger, "select x from y where a = ? and b = ? and c = ?", "aaa", null, 99); verify(logger, times(2)).isDebugEnabled(); verify(logger).debug("{} [{}]", "select x from y where a = ? and b = ? and c = ?", "'aaa', NULL, 99"); verifyNoMoreInteractions(logger); }