EnvVars { public static Set<String> extractReferencedVariables(EnvVar var) { String val = var.getValue(); Matcher matcher = REFERENCE_PATTERN.matcher(val); Set<String> ret = new HashSet<>(2); while (matcher.find()) { int start = matcher.start(); if (start > 0 && val.charAt(start - 1) == '$') { continue; } String refName = matcher.group().substring(2, matcher.group().length() - 1); ret.add(refName); } return ret; }  void apply(PodData podData, List<? extends Env> env); void apply(Container container, List<? extends Env> toApply); static Set<String> extractReferencedVariables(EnvVar var);  }
@Test(dataProvider = "detectReferencesTestValues") public void shouldDetectReferences(String value, Set<EnvVar> expected, String caseName) { assertEquals( extractReferencedVariables(var("name", value)), expected, caseName + ": just value"); assertEquals( extractReferencedVariables(var("name", "v" + value)), expected, caseName + ": value with prefix"); assertEquals( extractReferencedVariables(var("name", "v" + value + "v")), expected, caseName + ": value with prefix and postfix"); assertEquals( extractReferencedVariables(var("name", value + "v")), expected, caseName + ": value with postfix"); }
@Test public void shouldDetectMultipleReferences() throws Exception { EnvVar envVar = var("a", "$(b) $(c) $$(d)"); Set<String> refs = extractReferencedVariables(envVar); assertEquals(refs, new HashSet<>(Arrays.asList("b", "c"))); }