### Question:
SqlDataSourceUtils { public static boolean isNotNullColumn(DatabaseMetaData metaData, String tableName, String columnName) throws SQLException { try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) { if (!rs.next()) { throw new IllegalStateException("Did not find meta data for column '" + columnName + "' while checking for not-null constraint"); } int nullableCode = rs.getInt("NULLABLE"); if (nullableCode == DatabaseMetaData.columnNoNulls) { return true; } else if (nullableCode == DatabaseMetaData.columnNullableUnknown) { ConsoleLogger.warning("Unknown nullable status for column '" + columnName + "'"); } } return false; } private  SqlDataSourceUtils(); static void logSqlException(SQLException e); static Long getNullableLong(ResultSet rs, String columnName); static boolean isNotNullColumn(DatabaseMetaData metaData, String tableName,
                                          String columnName); static Object getColumnDefaultValue(DatabaseMetaData metaData, String tableName,
                                               String columnName);  }### Answer:
@Test public void shouldFetchNullableStatus() throws SQLException { String tableName = "data"; String columnName = "category"; ResultSet resultSet = mock(ResultSet.class); given(resultSet.getInt("NULLABLE")).willReturn(DatabaseMetaData.columnNullable); given(resultSet.next()).willReturn(true); DatabaseMetaData metaData = mock(DatabaseMetaData.class); given(metaData.getColumns(null, null, tableName, columnName)).willReturn(resultSet); boolean result = SqlDataSourceUtils.isNotNullColumn(metaData, tableName, columnName); assertThat(result, equalTo(false)); }
@Test public void shouldReturnFalseForUnknownNullableStatus() throws SQLException { String tableName = "comments"; String columnName = "author"; ResultSet resultSet = mock(ResultSet.class); given(resultSet.getInt("NULLABLE")).willReturn(DatabaseMetaData.columnNullableUnknown); given(resultSet.next()).willReturn(true); DatabaseMetaData metaData = mock(DatabaseMetaData.class); given(metaData.getColumns(null, null, tableName, columnName)).willReturn(resultSet); boolean result = SqlDataSourceUtils.isNotNullColumn(metaData, tableName, columnName); assertThat(result, equalTo(false)); }
@Test(expected = IllegalStateException.class) public void shouldThrowForUnknownColumnInNullableCheck() throws SQLException { String tableName = "data"; String columnName = "unknown"; ResultSet resultSet = mock(ResultSet.class); given(resultSet.next()).willReturn(false); DatabaseMetaData metaData = mock(DatabaseMetaData.class); given(metaData.getColumns(null, null, tableName, columnName)).willReturn(resultSet); SqlDataSourceUtils.isNotNullColumn(metaData, tableName, columnName); }