KeyForArgDecorator implements StringDecorator { @Override public String decorate(String str) { String[] objs = str.split("\\."); StringBuilder result = new StringBuilder(); if (objs.length > 1) { StringBuilder obj = new StringBuilder(); obj.append(objs[0]); result.append("(").append(obj); for (int i = 1; i < objs.length - 1; i++) { result.append("&&"); obj.append(".").append(objs[i]); result.append(obj); } result.append(")?").append(str).append(":null"); } else { result.append(str); } return result.toString(); }  @Override String decorate(String str);  }
@Test public void testDecorate() { System.out.println("decorate"); String result = instance.decorate("c"); assertThat(result).isEqualTo("c"); result = instance.decorate("c.user"); assertThat(result).isEqualTo("(c)?c.user:null"); result = instance.decorate("c.user.id"); assertThat(result).isEqualTo("(c&&c.user)?c.user.id:null"); }