### Question:
SpringValueExtractor { public SpringValue extract(String string) { SpringValue value = new SpringValue(); if (string==null) { return value; } String[] splitted = string.split("\\$\\{"); String firstNotEmpty=null; for (String split: splitted) { if (! StringUtils.isEmpty(split)) { firstNotEmpty=split.trim(); if (firstNotEmpty.length()>1 && firstNotEmpty.endsWith("}")) { firstNotEmpty=firstNotEmpty.substring(0,firstNotEmpty.length()-1); } break; } } if (firstNotEmpty==null) { value.key=string; return value; } int leftIndex = firstNotEmpty.indexOf(":"); if (leftIndex==-1) { value.key=firstNotEmpty; value.defaultValue=null; return value; } value.key= firstNotEmpty.substring(0,leftIndex); int startRight = leftIndex+1; if (firstNotEmpty.length()>startRight) { value.defaultValue=firstNotEmpty.substring(startRight); }else { value.defaultValue=""; } return value; }  SpringValue extract(String string); boolean isSpringValue(String string);  }### Answer:
@Test public void a_b_c_d_with_default_value_with_https_google_de_contains_default_value_https_gogole_de() { String result = extractorToTest.extract("${a.b.c.d:https: assertEquals("https: }
@Test public void a_b_c_d_with_default_value_with_https_google_de_contains_key_a_b_c_d() { String result = extractorToTest.extract("${a.b.c.d:https: assertEquals("a.b.c.d",result); }
@Test public void toDescription_uses_key_and_default_value_when_set() throws Exception { String result = extractorToTest.extract("${a.b.c.d:1234}").toDescription(); assertEquals("Key:a.b.c.d, per default:1234",result); }
@Test public void toDescription_uses_key_and_hint_about_not_optional_value_when_key_set_but_no_default() throws Exception { String result = extractorToTest.extract("${a.b.c.d}").toDescription(); assertEquals("Key:a.b.c.d, no default set so must be defined",result); }
@Test public void a_b_c_d_colon_1_2_3_extracted() { SpringValueExtractor.SpringValue extracted = extractorToTest.extract("${a.bc.d:123}"); assertNotNull(extracted); assertEquals("a.bc.d",extracted.getKey()); assertEquals("123",extracted.getDefaultValue()); }
@Test public void a_b_c_d_extracted() { SpringValueExtractor.SpringValue extracted = extractorToTest.extract("${a.bc.d}"); assertNotNull(extracted); assertEquals("a.bc.d",extracted.getKey()); assertEquals("",extracted.getDefaultValue()); }