예제 #1
0
 @Test
 public void shouldAddSecondParameterWithIndexTwoWhenTwoBooleanParametersGiven()
     throws SQLException {
   sqlBuilder.prepareStatement("query").withParameter(false).withParameter(true);
   verify(preparedStatementMock, atLeastOnce()).setBoolean(1, false);
   verify(preparedStatementMock, atLeastOnce()).setBoolean(2, true);
 }
예제 #2
0
 @Test
 public void shouldAddSecondParameterWithIndexTwoWhenTwoIntegerParametersGiven()
     throws SQLException {
   sqlBuilder.prepareStatement("query").withParameter(1).withParameter(2);
   verify(preparedStatementMock, atLeastOnce()).setInt(1, 1);
   verify(preparedStatementMock, atLeastOnce()).setInt(2, 2);
 }
예제 #3
0
 @Test
 public void shouldAddSecondParameterWithIndexTwoWhenTwoStringParametersGiven()
     throws SQLException {
   sqlBuilder.prepareStatement("query").withParameter("test").withParameter("second");
   verify(preparedStatementMock, atLeastOnce()).setString(1, "test");
   verify(preparedStatementMock, atLeastOnce()).setString(2, "second");
 }
예제 #4
0
 @Test
 public void shouldResetParameterIndexWhenContinueWithOnOpenStatementGiven() throws SQLException {
   sqlBuilder.prepareStatement("select 1 from dual");
   sqlBuilder.withParameter(true);
   sqlBuilder.withParameter(false);
   sqlBuilder.continueWith().prepareStatement("select 2 from dual");
   sqlBuilder.withParameter("test");
   verify(preparedStatementMock, times(1)).setBoolean(1, true);
   verify(preparedStatementMock, times(1)).setBoolean(2, false);
   verify(preparedStatementMock, times(1)).setString(1, "test");
 }
예제 #5
0
 @Test(expected = IllegalStateException.class)
 public void shouldThrowExceptionWhenParameterOnClosedBuilderGiven() throws SQLException {
   sqlBuilder.close();
   sqlBuilder.prepareStatement("bla");
 }
예제 #6
0
 @Test
 public void shouldAddParameterWhenStringParameterGiven() throws SQLException {
   sqlBuilder.prepareStatement("query").withParameter("test");
   verify(preparedStatementMock, atLeastOnce()).setString(1, "test");
 }
예제 #7
0
 @Test(expected = IllegalStateException.class)
 public void shouldThrowExceptionWhenClosedSqlBuilderGiven() throws SQLException {
   SqlBuilder sqlBuilder = new SqlBuilder(dataSourceMock);
   sqlBuilder.close();
   sqlBuilder.prepareStatement("some query");
 }
예제 #8
0
 @Test(expected = IllegalArgumentException.class)
 public void shouldThrowExceptionWhenNoSqlQueryGiven() throws SQLException {
   sqlBuilder.prepareStatement(null);
 }
예제 #9
0
 @Test
 public void shouldPrepareStatementWhenSqlQueryGiven() throws SQLException {
   sqlBuilder.prepareStatement("select 1 from dual");
   verify(connectionMock, atLeastOnce()).prepareStatement("select 1 from dual");
 }
예제 #10
0
 @Test
 public void shouldReturnResultSetWhenUpdateOnOpenStatementGiven() throws SQLException {
   sqlBuilder.prepareStatement("select 1 from dual");
   sqlBuilder.update();
   verify(preparedStatementMock, times(1)).executeUpdate();
 }
예제 #11
0
 @Test(expected = JdbcException.class)
 public void shouldThrowRuntimeExceptionWhenSqlExceptionGiven() throws SQLException {
   Mockito.doThrow(new SQLException("something bad happened")).when(connectionMock).close();
   sqlBuilder.prepareStatement("select 1 from dual");
   sqlBuilder.close();
 }
예제 #12
0
 @Test(expected = IllegalStateException.class)
 public void shouldThrowExceptionWhenUpdateOnClosedStatementGiven() throws SQLException {
   sqlBuilder.prepareStatement("select 1 from dual");
   sqlBuilder.close();
   sqlBuilder.update();
 }
예제 #13
0
 @Test
 public void shouldCloseStatementWhenContinueWithOnOpenStatementGiven() throws SQLException {
   sqlBuilder.prepareStatement("select 1 from dual");
   sqlBuilder.continueWith();
   verify(preparedStatementMock, times(1)).close();
 }
예제 #14
0
 @Test
 public void shouldEnableAutoCommitWhenWithoutTransactionGiven() throws SQLException {
   sqlBuilder.prepareStatement("select 1 from dual").withoutTransaction();
   verify(connectionMock, atLeastOnce()).setAutoCommit(true);
 }