static Optional<String> ensurePropertyAndGetWarning(
            Map<String, ? super String> props,
            String key,
            String expectedValue,
            String justification,
            boolean caseSensitive) {
        if (!props.containsKey(key)) {
            // Insert the expected value
            props.put(key, expectedValue);
            // But don't issue a warning to the user
            return Optional.empty();
        }

        String value = Objects.toString(props.get(key));
        boolean matchesExpectedValue = caseSensitive ? expectedValue.equals(value) : expectedValue.equalsIgnoreCase(value);
        if (matchesExpectedValue) {
            return Optional.empty();
        }

        // Insert the expected value
        props.put(key, expectedValue);

        justification = justification != null ? " " + justification : "";
        // And issue a warning to the user
        return Optional.of(String.format(
                "The value '%s' for the '%s' property will be ignored as it cannot be overridden%s. "
                        + "The value '%s' will be used instead.",
                value, key, justification, expectedValue
        ));
    }
@Test
    public void testNoOverrideWarning() {
        Map<String, ? super String> props = new HashMap<>();
        assertEquals(
                Optional.empty(),
                ConnectUtils.ensurePropertyAndGetWarning(props, "key", "value", "because i say so", true)
        );
        assertEquals("value", props.get("key"));

        props.clear();
        assertEquals(
                Optional.empty(),
                ConnectUtils.ensurePropertyAndGetWarning(props, "key", "value", "because i say so", false)
        );
        assertEquals("value", props.get("key"));

        props.clear();
        props.put("key", "value");
        assertEquals(
                Optional.empty(),
                ConnectUtils.ensurePropertyAndGetWarning(props, "key", "value", "because i say so", true)
        );
        assertEquals("value", props.get("key"));

        props.clear();
        props.put("key", "VALUE");
        assertEquals(
                Optional.empty(),
                ConnectUtils.ensurePropertyAndGetWarning(props, "key", "value", "because i say so", false)
        );
        assertEquals("VALUE", props.get("key"));
    }