@Test public void connectionMadeSQLFails() throws SQLException { final SQLInitializationPlugin sqlInitializationPlugin = new SQLInitializationPlugin( "INSERT INTO MyTables values(1, 'User');"); assertNotNull(sqlInitializationPlugin); when(connection.createStatement()).thenReturn(statement); when(statement.execute(anyString())).thenThrow(new SQLException("Reason")); assertThrows(IllegalStateException.class, () -> sqlInitializationPlugin.connectionMade("name", connection)); }
@Override public void connectionMade(final String name, final Connection connection) { try (final Statement statement = connection.createStatement()) { statement.execute(sql); } catch (SQLException e) { throw new IllegalStateException(String.format("Could not init database using SQL script: \"%s\"", sql)); } }
SQLInitializationPlugin implements InitializationPlugin { @Override public void connectionMade(final String name, final Connection connection) { try (final Statement statement = connection.createStatement()) { statement.execute(sql); } catch (SQLException e) { throw new IllegalStateException(String.format("Could not init database using SQL script: \"%s\"", sql)); } } }
SQLInitializationPlugin implements InitializationPlugin { @Override public void connectionMade(final String name, final Connection connection) { try (final Statement statement = connection.createStatement()) { statement.execute(sql); } catch (SQLException e) { throw new IllegalStateException(String.format("Could not init database using SQL script: \"%s\"", sql)); } } SQLInitializationPlugin(final String sql); }
SQLInitializationPlugin implements InitializationPlugin { @Override public void connectionMade(final String name, final Connection connection) { try (final Statement statement = connection.createStatement()) { statement.execute(sql); } catch (SQLException e) { throw new IllegalStateException(String.format("Could not init database using SQL script: \"%s\"", sql)); } } SQLInitializationPlugin(final String sql); @Override void connectionMade(final String name, final Connection connection); }
SQLInitializationPlugin implements InitializationPlugin { @Override public void connectionMade(final String name, final Connection connection) { try (final Statement statement = connection.createStatement()) { statement.execute(sql); } catch (SQLException e) { throw new IllegalStateException(String.format("Could not init database using SQL script: \"%s\"", sql)); } } SQLInitializationPlugin(final String sql); @Override void connectionMade(final String name, final Connection connection);  }