@Test
 public void enhanceShouldNotEnhanceTwice() {
   ResultSet mockResultSet = mock(ResultSet.class);
   EnhancedResultSet enhanced1 = ResultSets.enhance(mockResultSet);
   EnhancedResultSet enhanced2 = ResultSets.enhance(enhanced1);
   assertSame(enhanced1, enhanced2);
 }
  @Test
  public void getNullableLongWithColumnNameWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getLong("foo")).thenReturn(7L);

    assertEquals(7L, ResultSets.getNullableLong(mockResultSet, "foo").longValue());
    assertEquals(7L, ResultSets.enhance(mockResultSet).getNullableLong("foo").longValue());

    when(mockResultSet.getLong("foo")).thenReturn(0L);
    when(mockResultSet.wasNull()).thenReturn(true);
    assertNull(ResultSets.getNullableLong(mockResultSet, "foo"));
    assertNull(ResultSets.enhance(mockResultSet).getNullableLong("foo"));
  }
  @Test
  public void getNullableIntWithColumnNameWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getInt("foo")).thenReturn(7);

    assertEquals(7, ResultSets.getNullableInt(mockResultSet, "foo").intValue());
    assertEquals(7, ResultSets.enhance(mockResultSet).getNullableInt("foo").intValue());

    when(mockResultSet.getInt("foo")).thenReturn(0);
    when(mockResultSet.wasNull()).thenReturn(true);
    assertNull(ResultSets.getNullableInt(mockResultSet, "foo"));
    assertNull(ResultSets.enhance(mockResultSet).getNullableInt("foo"));
  }
  @Test
  public void getEnumFromNameWithColumnIndexWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getString(2)).thenReturn("FOO");

    assertEquals(TestEnum.FOO, ResultSets.getEnumFromName(mockResultSet, 2, TestEnum.class));
    assertEquals(
        TestEnum.FOO, ResultSets.enhance(mockResultSet).getEnumFromName(2, TestEnum.class));

    when(mockResultSet.getString(2)).thenReturn(null);
    assertNull(ResultSets.getEnumFromName(mockResultSet, 2, TestEnum.class));
    assertNull(ResultSets.enhance(mockResultSet).getEnumFromName(2, TestEnum.class));
  }
  @Test
  public void getNullableByteWithColumnIndexWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getByte(2)).thenReturn((byte) 7);

    assertEquals(7, ResultSets.getNullableByte(mockResultSet, 2).byteValue());
    assertEquals(7, ResultSets.enhance(mockResultSet).getNullableByte(2).byteValue());

    when(mockResultSet.getByte(2)).thenReturn((byte) 0);
    when(mockResultSet.wasNull()).thenReturn(true);
    assertNull(ResultSets.getNullableByte(mockResultSet, 2));
    assertNull(ResultSets.enhance(mockResultSet).getNullableByte(2));
  }
  @Test
  public void getNullableFloatWithColumnIndexWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getFloat(2)).thenReturn(7.0F);

    assertEquals(7.0F, ResultSets.getNullableFloat(mockResultSet, 2).floatValue(), 0.0001);
    assertEquals(7.0F, ResultSets.enhance(mockResultSet).getNullableFloat(2).floatValue(), 0.0001);

    when(mockResultSet.getFloat(2)).thenReturn(0.0F);
    when(mockResultSet.wasNull()).thenReturn(true);
    assertNull(ResultSets.getNullableFloat(mockResultSet, 2));
    assertNull(ResultSets.enhance(mockResultSet).getNullableFloat(2));
  }
  @Test
  public void getNullableBooleanWithColumnNameWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getBoolean("foo")).thenReturn(true);

    assertEquals(true, ResultSets.getNullableBoolean(mockResultSet, "foo").booleanValue());
    assertEquals(true, ResultSets.enhance(mockResultSet).getNullableBoolean("foo").booleanValue());

    when(mockResultSet.getBoolean("foo")).thenReturn(false);
    when(mockResultSet.wasNull()).thenReturn(true);
    assertNull(ResultSets.getNullableBoolean(mockResultSet, "foo"));
    assertNull(ResultSets.enhance(mockResultSet).getNullableBoolean("foo"));
  }
  @Test
  public void getEnumFromOrdinalWithColumnIndexWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getInt(2)).thenReturn(0);

    assertEquals(TestEnum.FOO, ResultSets.getEnumFromOrdinal(mockResultSet, 2, TestEnum.class));
    assertEquals(
        TestEnum.FOO, ResultSets.enhance(mockResultSet).getEnumFromOrdinal(2, TestEnum.class));

    when(mockResultSet.getInt(2)).thenReturn(0);
    when(mockResultSet.wasNull()).thenReturn(true);
    assertNull(ResultSets.getEnumFromOrdinal(mockResultSet, 2, TestEnum.class));
    assertNull(ResultSets.enhance(mockResultSet).getEnumFromOrdinal(2, TestEnum.class));
  }
  @Test
  public void getNullableDoubleWithColumnNameWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getDouble("foo")).thenReturn(7.0);

    assertEquals(7.0, ResultSets.getNullableDouble(mockResultSet, "foo").doubleValue(), 0.0001);
    assertEquals(
        7.0, ResultSets.enhance(mockResultSet).getNullableDouble("foo").doubleValue(), 0.0001);

    when(mockResultSet.getDouble("foo")).thenReturn(0.0);
    when(mockResultSet.wasNull()).thenReturn(true);
    assertNull(ResultSets.getNullableDouble(mockResultSet, "foo"));
    assertNull(ResultSets.enhance(mockResultSet).getNullableDouble("foo"));
  }
示例#10
0
  @Test
  public void methodFromResultSetWorks() throws SQLException {
    ResultSet mockResultSet = mock(ResultSet.class);
    when(mockResultSet.getInt("foo")).thenReturn(2);

    assertEquals(2, ResultSets.enhance(mockResultSet).getInt("foo"));
  }
示例#11
0
 @Test
 public void equalsReturnsTrueOnSameEnhancedStatement() {
   ResultSet mockResultSet = mock(ResultSet.class);
   EnhancedResultSet enhanced = ResultSets.enhance(mockResultSet);
   assertTrue(enhanced.equals(enhanced));
 }
示例#12
0
 @Test(expected = IllegalStateException.class)
 public void getEnumFromOrdinalWithColumnNameThrowsIllegalStateException2() throws SQLException {
   ResultSet mockResultSet = mock(ResultSet.class);
   when(mockResultSet.getInt("enum_column")).thenReturn(2);
   ResultSets.enhance(mockResultSet).getEnumFromOrdinal("enum_column", TestEnum.class);
 }
示例#13
0
 @Test(expected = IllegalStateException.class)
 public void getEnumFromOrdinalWithColumnIndexThrowsIllegalStateException() throws SQLException {
   ResultSet mockResultSet = mock(ResultSet.class);
   when(mockResultSet.getInt(2)).thenReturn(2);
   ResultSets.getEnumFromOrdinal(mockResultSet, 2, TestEnum.class);
 }
示例#14
0
 @Test(expected = IllegalStateException.class)
 public void getEnumFromNameWithColumnIndexThrowsIllegalStateException2() throws SQLException {
   ResultSet mockResultSet = mock(ResultSet.class);
   when(mockResultSet.getString(2)).thenReturn("HELLO");
   ResultSets.enhance(mockResultSet).getEnumFromName(2, TestEnum.class);
 }
示例#15
0
 @Test(expected = IllegalStateException.class)
 public void getEnumFromNameWithColumnNameThrowsIllegalStateException() throws SQLException {
   ResultSet mockResultSet = mock(ResultSet.class);
   when(mockResultSet.getString("enum_column")).thenReturn("HELLO");
   ResultSets.getEnumFromName(mockResultSet, "enum_column", TestEnum.class);
 }