SQLExecutor { public <T> List<T> execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLExecutorCallback<T> callback) throws SQLException { return execute(inputGroups, null, callback); }  List<T> execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLExecutorCallback<T> callback); @SuppressWarnings("unchecked") List<T> execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLExecutorCallback<T> firstCallback, final SQLExecutorCallback<T> callback);  }
@Test public void assertExecute() throws SQLException { ExecutorKernel kernel = mock(ExecutorKernel.class); when(kernel.execute(anyCollection(), any(), any(), anyBoolean())).thenReturn(Collections.singletonList("test")); SQLExecutor sqlExecutor = new SQLExecutor(kernel, false); List<?> actual1 = sqlExecutor.execute(Collections.emptyList(), null); assertThat(actual1, is(Collections.singletonList("test"))); List<?> actual2 = sqlExecutor.execute(Collections.emptyList(), null, null); assertThat(actual2, is(Collections.singletonList("test"))); }
@Test public void assertExecuteSQLException() { try { ExecutorKernel kernel = mock(ExecutorKernel.class); when(kernel.execute(anyCollection(), any(), any(), anyBoolean())).thenThrow(new SQLException("TestSQLException")); SQLExecutor sqlExecutor = new SQLExecutor(kernel, false); sqlExecutor.execute(Collections.emptyList(), null); } catch (final SQLException ex) { assertThat(ex.getMessage(), is("TestSQLException")); } }
@Test public void assertExecuteNotThrownSQLException() throws SQLException { ExecutorKernel kernel = mock(ExecutorKernel.class); when(kernel.execute(anyCollection(), any(), any(), anyBoolean())).thenThrow(new SQLException("TestSQLException")); SQLExecutor sqlExecutor = new SQLExecutor(kernel, false); ExecutorExceptionHandler.setExceptionThrown(false); List<?> actual = sqlExecutor.execute(Collections.emptyList(), null); assertThat(actual, is(Collections.emptyList())); }