Class ResultSetMockBuilder

java.lang.Object
com.atlassian.bamboo.testutils.ResultSetMockBuilder

public class ResultSetMockBuilder extends Object
A builder used to create mocks of SQL ResultSet.

Example usage:

     // with named columns
     final ResultSet fetchRowsResult = new ResultSetMockBuilder()
         .addRow()
             .addColumnValue("name", "John")
             .addColumnValue("age", 21)
         .addRow()
             .addColumnValue("name", "James")
             .addColumnValue("age", "30")
         .build();

     // with indexed columns
     final ResultSet countRowsResult = new ResultSetMockBuilder()
         .addRow()
         .addColumnValue(totalRows)
         .build();
 
  • Constructor Details

    • ResultSetMockBuilder

      public ResultSetMockBuilder()
  • Method Details

    • addRow

      public ResultSetMockBuilder addRow()
      Adds next row to the mocked ResultSet.
    • addColumnValue

      public ResultSetMockBuilder addColumnValue(@Nullable @Nullable Object value)
      Adds next column value to the current row of the mocked ResultSet.

      Calling this method will not assign a column name to this value, so retrieval from the result set will only be possible by fetching by column index. Remember that column indexing for the ResultSet starts from 1, and not from 0.

      Note: at least one row must be added by calling addRow() prior to adding column values.

    • addColumnValue

      public ResultSetMockBuilder addColumnValue(@NotNull @NotNull String columnName, @Nullable @Nullable Object value)
      Adds next column value to the current row of the mocked ResultSet and assigns the column name to it.

      Retrieval of this value will be possible both by column index and by column name. Remember that column indexing for the ResultSet starts from 1, and not from 0.

      Note: at least one row must be added by calling addRow() prior to adding column values.

    • build

      public ResultSet build()
      Builds the mock of ResultSet.