MetaDataConnection implements Connection { @Override public String getCatalog() { try { return connection.getCatalog(); } catch (final SQLException ex) { return null; } }  @Override String getCatalog(); @Override void setCatalog(final String catalog); @Override String getSchema(); @Override void setSchema(final String schema); @Override Statement createStatement(); @Override Statement createStatement(final int resultSetType, final int resultSetConcurrency); @Override Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability); @Override PreparedStatement prepareStatement(final String sql); @Override PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency); @Override PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability); @Override PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys); @Override PreparedStatement prepareStatement(final String sql, final int[] columnIndexes); @Override PreparedStatement prepareStatement(final String sql, final String[] columnNames); @Override CallableStatement prepareCall(final String sql); @Override CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency); @Override CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability); @Override String nativeSQL(final String sql); @Override void setAutoCommit(final boolean autoCommit); @Override boolean getAutoCommit(); @Override void commit(); @Override void close(); @Override boolean isClosed(); @Override DatabaseMetaData getMetaData(); @Override void setReadOnly(final boolean readOnly); @Override boolean isReadOnly(); @Override void setTransactionIsolation(final int level); @Override int getTransactionIsolation(); @Override SQLWarning getWarnings(); @Override void clearWarnings(); @Override Map<String, Class<?>> getTypeMap(); @Override void setTypeMap(final Map<String, Class<?>> map); @Override void setHoldability(final int holdability); @Override int getHoldability(); @Override Savepoint setSavepoint(); @Override Savepoint setSavepoint(final String name); @Override void rollback(); @Override void rollback(final Savepoint savepoint); @Override void releaseSavepoint(final Savepoint savepoint); @Override Clob createClob(); @Override Blob createBlob(); @Override NClob createNClob(); @Override SQLXML createSQLXML(); @Override boolean isValid(final int timeout); @Override void setClientInfo(final String name, final String value); @Override void setClientInfo(final Properties props); @Override String getClientInfo(final String name); @Override Properties getClientInfo(); @Override Array createArrayOf(final String typeName, final Object[] elements); @Override Struct createStruct(final String typeName, final Object[] attributes); @Override void abort(final Executor executor); @Override void setNetworkTimeout(final Executor executor, final int milliseconds); @Override int getNetworkTimeout(); @Override T unwrap(final Class<T> iface); @Override boolean isWrapperFor(final Class<?> iface);  }
@Test public void assertGetCatalog() throws SQLException { when(connection.getCatalog()).thenReturn(TEST_CATALOG); MetaDataConnection metaDataConnection = new MetaDataConnection(connection); assertThat(metaDataConnection.getCatalog(), is(TEST_CATALOG)); }
@Test public void assertGetCatalogReturnNullWhenThrowsSQLException() throws SQLException { when(connection.getCatalog()).thenThrow(SQLException.class); MetaDataConnection metaDataConnection = new MetaDataConnection(connection); assertNull(metaDataConnection.getCatalog()); }