Ejemplo n.º 1
0
  @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));
  }
Ejemplo n.º 2
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);
 }