GlobalVariableNames { @VisibleForTesting static Map<String, Set<String>> environments() { InputStream stream = GlobalVariableNames.class.getResourceAsStream(GLOBALS_FILE); InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); try { String str = CharStreams.toString(reader); Type stringStringMap = new TypeToken<Map<String, Set<String>>>(){}.getType(); return gson.fromJson(str, stringStringMap); } catch (IOException e) { throw new IllegalStateException("Cannot load " + GLOBALS_FILE, e); } } GlobalVariableNames(@Nullable Configuration configuration); Set<String> names(); static final String ENVIRONMENTS_PROPERTY_KEY; static final String ENVIRONMENTS_DEFAULT_VALUE; static final String GLOBALS_PROPERTY_KEY; static final String GLOBALS_DEFAULT_VALUE; }
@Test public void test_default_do_not_intersect() throws Exception { Set<String> defaultEnvironments = Sets.newHashSet(GlobalVariableNames.ENVIRONMENTS_DEFAULT_VALUE.split(",")).stream() .map(String::trim) .collect(Collectors.toSet()); Set<String> defaultGlobals = Sets.newHashSet(GlobalVariableNames.GLOBALS_DEFAULT_VALUE.split(",")).stream() .map(String::trim) .collect(Collectors.toSet()); Map<String, Set<String>> environments = GlobalVariableNames.environments(); Set<String> allNamesFromAllEnvironments = environments.entrySet().stream() .filter(entry -> defaultEnvironments.contains(entry.getKey())) .map(Entry::getValue) .flatMap(Collection::stream) .collect(Collectors.toSet()); Set<String> intersection = new HashSet<>(allNamesFromAllEnvironments); intersection.retainAll(defaultGlobals); assertThat(intersection).isEmpty(); }