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 testOverrideWarning() {
        Map<String, ? super String> props = new HashMap<>();
        props.put("\u1984", "little brother");
        String expectedWarning = "The value 'little brother' for the '\u1984' property will be ignored as it cannot be overridden "
                + "thanks to newly-introduced federal legislation. "
                + "The value 'big brother' will be used instead.";
        assertEquals(
                Optional.of(expectedWarning),
                ConnectUtils.ensurePropertyAndGetWarning(
                        props,
                        "\u1984",
                        "big brother",
                        "thanks to newly-introduced federal legislation",
                        false)
        );
        assertEquals(Collections.singletonMap("\u1984", "big brother"), props);

        props.clear();
        props.put("\u1984", "BIG BROTHER");
        expectedWarning = "The value 'BIG BROTHER' for the '\u1984' property will be ignored as it cannot be overridden "
                + "thanks to newly-introduced federal legislation. "
                + "The value 'big brother' will be used instead.";
        assertEquals(
                Optional.of(expectedWarning),
                ConnectUtils.ensurePropertyAndGetWarning(
                        props,
                        "\u1984",
                        "big brother",
                        "thanks to newly-introduced federal legislation",
                        true)
        );
        assertEquals(Collections.singletonMap("\u1984", "big brother"), props);
    }