### Question:
TemplateParse { public List<Segment> parseSegments(String template) { List<Segment> segments = new ArrayList<Segment>(); List<String> strings = parse(template); for (String s : strings) { if (isVariable(s)) { String name = s.substring(2, s.length() - 1); segments.add(new Variable(name)); } else { segments.add(new PlainText(s)); } } return segments; }  List<Segment> parseSegments(String template); List<String> parse(String template);  }### Answer:
@Test public void parsingTemplateIntoSegmentObjects() throws Exception { TemplateParse p = new TemplateParse(); List<Segment> segments = p.parseSegments("a ${b} c ${d}"); assertSegments(segments, new PlainText("a "), new Variable( "b"), new PlainText(" c "), new Variable("d")); }