### Question:
ResultSetSchemaFactory { static Schema createSchema(ResultSetMetaData metaData) throws SQLException { return new ResultSetSchemaFactory(metaData).createSchema(); }    }### Answer:
@Test public void test() throws SQLException { when(Integer.valueOf(metaData.getColumnCount())).thenReturn(Integer.valueOf(2)); doReturn(String.class.getName()).when(metaData).getColumnClassName(1); doReturn(Integer.class.getName()).when(metaData).getColumnClassName(2); doReturn("a").when(metaData).getColumnName(1); doReturn("b").when(metaData).getColumnName(2); Schema schema = ResultSetSchemaFactory.createSchema(metaData); assertThat(schema.getColumns()).hasSize(2); assertThat(schema.getColumns()).contains(Column.of("a", String.class)); assertThat(schema.getColumns()).contains(Column.of("b", Integer.class)); }
@Test public void testClassNotFound() throws SQLException { when(Integer.valueOf(metaData.getColumnCount())).thenReturn(Integer.valueOf(1)); when(metaData.getColumnClassName(1)).thenReturn("foo.bar.Baz"); Schema schema = ResultSetSchemaFactory.createSchema(metaData); assertThat(schema.getColumns()).isEmpty(); }
@Test public void testTableName() throws SQLException { when(Integer.valueOf(metaData.getColumnCount())).thenReturn(Integer.valueOf(1)); when(metaData.getColumnClassName(1)).thenReturn(String.class.getName()); when(metaData.getColumnName(1)).thenReturn("a"); when(metaData.getTableName(1)).thenReturn("t"); Schema schema = ResultSetSchemaFactory.createSchema(metaData); assertThat(schema.getColumns()).hasSize(1); assertThat(schema.getColumns()).contains(Column.of("a", String.class, "t")); }