### Question:
DefaultValueService { protected String process(Object obj, String definition) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { StringBuffer value = new StringBuffer(definition); Pattern pattern = Pattern.compile("\\$\\{.+?\\}"); Matcher matcher = pattern.matcher(value); while (matcher.find()) { String path = matcher.group(); path = path.substring(2, path.length() - 1); String replacement = getPathValue(obj, path); value.replace(matcher.start(), matcher.end(), "" + replacement); matcher.reset(value); } return value.toString(); } @Autowired  DefaultValueService(@NonNull final DefaultValueRepository repository,
                        @NonNull final ProjectRepository projectRepository); Map<String, Object> getValues(DefaultValue.DefaultValueType type, Long projectId); Map<String, Object> getValues(DefaultValue.DefaultValueType type, String projectSlug); void saveDefaultValues(@NonNull final Project project, @NonNull final U entity);  }### Answer:
@Test public void shouldProcessBuildValue1() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { Bar bar = new Bar( null, null, null, null, new Foo(1L), null, null, null); String res = tested.process(bar, "${id}_${test4.id}_test"); Assert.assertEquals("null_1_test", res); }
@Test public void shouldProcessBuildValue2() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { Bar bar = new Bar( null, null, null, null, null, null, new Foo[]{new Foo(1L)}, null); String res = tested.process(bar, "${id}_${array[0].id}_test"); Assert.assertEquals("null_1_test", res); }
@Test public void shouldProcessBuildValue3() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { Bar bar = new Bar( null, null, null, null, null, null, null, Collections.singletonList(new Foo(1L))); String res = tested.process(bar, "${id}_${list[0].id}_test"); Assert.assertEquals("null_1_test", res); }