From 5efc24d939aee054448393bf5f309926023f1dd2 Mon Sep 17 00:00:00 2001 From: Sven Hettwer Date: Thu, 7 Feb 2019 13:42:54 +0100 Subject: [PATCH] (#29) Ensure that getNextRow throws SQLException instead of IndexOutOfBounds --- .../citrus/db/driver/dataset/DataSet.java | 6 +++++- .../citrus/db/driver/dataset/DataSetTest.java | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 driver/src/test/java/com/consol/citrus/db/driver/dataset/DataSetTest.java diff --git a/driver/src/main/java/com/consol/citrus/db/driver/dataset/DataSet.java b/driver/src/main/java/com/consol/citrus/db/driver/dataset/DataSet.java index 4bc42b4..645c527 100644 --- a/driver/src/main/java/com/consol/citrus/db/driver/dataset/DataSet.java +++ b/driver/src/main/java/com/consol/citrus/db/driver/dataset/DataSet.java @@ -46,7 +46,11 @@ public class DataSet { */ public Row getNextRow() throws SQLException { checkNotClosed(); - return rows.get(cursor.getAndIncrement()); + try{ + return rows.get(cursor.getAndIncrement()); + }catch (IndexOutOfBoundsException e){ + throw new SQLException("No further row in dataset", e); + } } /** diff --git a/driver/src/test/java/com/consol/citrus/db/driver/dataset/DataSetTest.java b/driver/src/test/java/com/consol/citrus/db/driver/dataset/DataSetTest.java new file mode 100644 index 0000000..5990a8e --- /dev/null +++ b/driver/src/test/java/com/consol/citrus/db/driver/dataset/DataSetTest.java @@ -0,0 +1,21 @@ +package com.consol.citrus.db.driver.dataset; + +import org.testng.annotations.Test; + +import java.sql.SQLException; + +public class DataSetTest { + + private DataSet dataSet = new DataSet(); + + @Test(expectedExceptions = SQLException.class) + public void emptyDataSetThrowsExceptionOnGetNextRow() throws SQLException { + + //WHEN + dataSet.getNextRow(); + + //THEN + //exception + } + +} \ No newline at end of file