PropertyValidator { void validate(Set<String> keys) { List<String> notUsedKeys = new ArrayList<>(); for (String key : keys) { if (!usedProperties.contains(key)) notUsedKeys.add(key); } if (!notUsedKeys.isEmpty()) { throw new Error("found not used properties, please remove unnecessary config, keys=" + notUsedKeys); } }    }
@Test void validate() { validator.usedProperties.add("app.usedKey"); assertThatThrownBy(() -> validator.validate(Set.of("app.usedKey", "app.notUsedKey"))) .isInstanceOf(Error.class) .hasMessageContaining("found not used properties") .hasMessageContaining("keys=[app.notUsedKey]"); }