### Question:
ConnectorOptions { public static <T> T extractOptionAndMap(Map<String, ?> options, String key, Function<? super String, T> mappingFn, T defaultValue) { if (options == null) { return defaultValue; } try { return Optional.ofNullable(options.get(key)) .map(Object::toString) .filter(v -> v.length() > 0) .map(mappingFn) .orElse(defaultValue); } catch (Exception ex) { LOG.error("Evaluation of option '" + key + "' failed. Returning default value.", ex); return defaultValue; } } private  ConnectorOptions(); static String extractOption(Map<String, ?> options, String key, String defaultValue); static String extractOption(Map<String, ?> options, String key); static String popOption(Map<String, ?> options, String key); static T extractOptionAndMap(Map<String, ?> options, String key,
                                                                    Function<? super String, T> mappingFn, T defaultValue); static T extractOptionAndMap(Map<String, ?> options, String key,
                                                                    Function<? super String, T> mappingFn); static void extractOptionAndConsume(Map<String, ?> options, String key,
                                                                   Consumer<String> consumer); static T extractOptionAsType(Map<String, ?> options,
                                                            String key, Class<T> requiredClass, T defaultValue); static T extractOptionAsType(Map<String, ?> options,
                                                            String key, Class<T> requiredClass);  }### Answer:
@Test public void testStringValueAndMap() throws Exception { put(key, value); assertEquals((Long) 1L, ConnectorOptions.extractOptionAndMap(parameters, key, this::convertLong)); assertNull(ConnectorOptions.extractOptionAndMap(parameters, missingKey, this::convertLong)); }
@Test public void testStringValueAndMapWithDefault() { Long defaultValue = 2L; put(key, value); assertEquals((Long) 1L, ConnectorOptions.extractOptionAndMap(parameters, key, this::convertLong, defaultValue)); assertEquals(defaultValue, ConnectorOptions.extractOptionAndMap(parameters, missingKey, this::convertLong, defaultValue)); }
@Test public void testStringValueAndMapToBooleanWithDefault() { put(key, Boolean.toString(true)); assertEquals(Boolean.TRUE, ConnectorOptions.extractOptionAndMap(parameters, key, Boolean::valueOf, false)); assertEquals(Boolean.FALSE, ConnectorOptions.extractOptionAndMap(parameters, missingKey, Boolean::valueOf, false)); put(key, "NotABoolean"); assertEquals(Boolean.FALSE, ConnectorOptions.extractOptionAndMap(parameters, key, Boolean::valueOf, false)); }
@Test public void testStringValueAndMapToIntWithDefault() throws Exception { put(key, 2); assertTrue(2 == ConnectorOptions.extractOptionAndMap(parameters, key, Integer::parseInt, 3)); assertTrue(3 == ConnectorOptions.extractOptionAndMap(parameters, missingKey, Integer::parseInt, 3)); put(key, "NotAnInt"); assertTrue(-1 == ConnectorOptions.extractOptionAndMap(parameters, key, Integer::parseInt, -1)); }