Skip to content

Commit

Permalink
(#29) Fixed contract clash between Dataset JdbcCallableStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Feb 7, 2019
1 parent e210cf4 commit 580a16b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public void registerOutParameter(final int parameterIndex, final int sqlType, fi

@Override
public boolean wasNull() throws SQLException {
return Objects.isNull(getDataRow().getLastValue());
final Row dataRow = getDataRow();
if(dataRow == null){
return false;
}
return Objects.isNull(dataRow.getLastValue());
}

@Override
Expand Down
31 changes: 20 additions & 11 deletions driver/src/main/java/com/consol/citrus/db/driver/JdbcResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@

package com.consol.citrus.db.driver;

import com.consol.citrus.db.driver.dataset.DataSet;
import com.consol.citrus.db.driver.data.Row;
import com.consol.citrus.db.driver.dataset.DataSet;

import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;

Expand All @@ -48,14 +64,7 @@ public JdbcResultSet(DataSet dataSet, JdbcStatement statement) throws SQLExcepti

@Override
public boolean next() throws SQLException {
try {
row = dataSet.getNextRow();
} catch(SQLException ex) {
throw ex;
} catch(Exception ex) {
return false;
}

row = dataSet.getNextRow();
return row != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ public class DataSet {
/**
* Gets next row in this result set based on cursor position.
* @return The next row of the dataset
* @throws SQLException In case the DataSet has been closed or no further rows are availabe
* @throws SQLException In case the DataSet has been closed or no further rows are available
*/
public Row getNextRow() throws SQLException {
checkNotClosed();
try{
return rows.get(cursor.getAndIncrement());
}catch (final IndexOutOfBoundsException cause){
throw new SQLException("No further row in dataset", cause);

final int index = cursor.getAndIncrement();
if(rows.size() <= index){
return null;
}

return rows.get(index);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,17 +759,17 @@ void testGetBigDecimalByName() throws SQLException {
verifyConversion(aBigDecimal, BigDecimal.class);
}

@Test(expectedExceptions = SQLException.class)
void testWasNullThrowsException() throws SQLException {
@Test
void testWasNullReturnsFalseAsDefault() throws SQLException {

//GIVEN
final JdbcCallableStatement callableStatement = generateCallableStatement();

//WHEN
callableStatement.wasNull();
final boolean wasNull = callableStatement.wasNull();

//THEN
//exception
assertFalse(wasNull);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package com.consol.citrus.db.driver.dataset;

import com.consol.citrus.db.driver.data.Row;
import com.jparams.verifier.tostring.ToStringVerifier;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.testng.annotations.Test;

import java.sql.SQLException;

import static org.testng.Assert.assertNull;

public class DataSetTest {

private DataSet dataSet = new DataSet();

@Test(expectedExceptions = SQLException.class)
public void emptyDataSetThrowsExceptionOnGetNextRow() throws SQLException {
@Test
public void emptyDataSetReturnsNullOnGetNextRow() throws SQLException {

//WHEN
dataSet.getNextRow();
final Row nextRow = dataSet.getNextRow();

//THEN
//exception
assertNull(nextRow);
}

@Test
Expand Down

0 comments on commit 580a16b

Please sign in to comment.