|
25 | 25 | import static org.junit.Assert.assertTrue; |
26 | 26 | import static org.junit.Assert.fail; |
27 | 27 | import static org.mockito.Mockito.mock; |
| 28 | +import static org.mockito.Mockito.when; |
28 | 29 |
|
29 | 30 | import com.google.cloud.ByteArray; |
30 | 31 | import com.google.cloud.Date; |
@@ -802,6 +803,32 @@ public void testGetMetaData() throws SQLException { |
802 | 803 | assertNotNull(metadata); |
803 | 804 | } |
804 | 805 |
|
| 806 | + @Test |
| 807 | + public void testGetMetaDataBeforeNext() throws SQLException { |
| 808 | + ResultSet spannerResultSet = mock(ResultSet.class); |
| 809 | + when(spannerResultSet.next()).thenReturn(true, false); |
| 810 | + |
| 811 | + JdbcResultSet resultSet = JdbcResultSet.of(spannerResultSet); |
| 812 | + assertNotNull(resultSet.getMetaData()); |
| 813 | + assertTrue(resultSet.next()); |
| 814 | + assertFalse(resultSet.next()); |
| 815 | + } |
| 816 | + |
| 817 | + @Test |
| 818 | + public void testGetMetaDataTwiceBeforeNext() throws SQLException { |
| 819 | + ResultSet spannerResultSet = mock(ResultSet.class); |
| 820 | + when(spannerResultSet.next()).thenReturn(true, false); |
| 821 | + |
| 822 | + JdbcResultSet resultSet = JdbcResultSet.of(spannerResultSet); |
| 823 | + assertNotNull(resultSet.getMetaData()); |
| 824 | + assertNotNull(resultSet.getMetaData()); |
| 825 | + |
| 826 | + // This would have returned false before the fix in |
| 827 | + // https://github.com/googleapis/java-spanner-jdbc/pull/323 |
| 828 | + assertTrue(resultSet.next()); |
| 829 | + assertFalse(resultSet.next()); |
| 830 | + } |
| 831 | + |
805 | 832 | @Test |
806 | 833 | public void testFindColumn() throws SQLException { |
807 | 834 | assertEquals(2, subject.findColumn(STRING_COL_NOT_NULL)); |
|
0 commit comments