PropertyBuilder { public static Property create(Field field, Object value) { String name = field.getName(); Type type = field.getType(); if (type.isCombobox()) { ComboboxHolder holder = new ComboboxHolder(field); if (holder.isCollection()) { if (holder.getTypeClassName().equals(List.class.getName())) { return new CollectionProperty(name, value, new ArrayList(), holder.getUnderlyingType()); } else if (holder.getTypeClassName().equals(Set.class.getName())) { return new CollectionProperty(name, value, new HashSet(), holder.getUnderlyingType()); } } } return create(name, value, field.getType().getTypeClassName()); } private  PropertyBuilder(); static Property create(Field field, Object value); static Property create(String name, Object value, Class type); static Property create(String name, Object value, String type); static Property create(String name, Object value, String type, String operator); static Property createRelationProperty(String jdoVariableName, String name, Object value, String type); static Property createRelationProperty(String jdoVariableName, String name, Object value, String type, String operator); static CollectionProperty createRelationPropertyForComboboxCollection(String jdoVariable, String name, Object value, String type);  }
@Test public void shouldCreatePropertyByFieldAndValue() throws Exception { Type type = new Type(String.class); Field field = new Field(null, "ala", "ala",type, true, false, false); assertProperty(PropertyBuilder.create(field, "cat"), "ala", "cat"); }
@Test public void shouldCreatePropertyByNameAndValue() throws Exception { assertProperty(PropertyBuilder.create("test", 100L, Long.class.getName()), "test", 100L); }
@Test public void shouldGenerateAppropriatePropertyType() throws Exception { Set<String> set = new HashSet<>(); Range<Integer> range = new Range<>(0, 1); Type type = new Type("mds.field.combobox", "", List.class); Entity entity = new Entity("org.motechproject.mds.Sample"); Field field = new Field(entity, "roles","roles", type, true, false, false); assertProperty( PropertyBuilder.create("roles", 1L, Long.class.getName()), EqualProperty.class, "roles", 1L ); field.addSetting(new FieldSetting(field, new TypeSetting(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS), "true")); assertProperty( PropertyBuilder.create(field, "role"), CollectionProperty.class, "roles", Arrays.asList("role") ); field.addSetting(new FieldSetting(field, new TypeSetting(Constants.Settings.ALLOW_USER_SUPPLIED), "true")); assertProperty( PropertyBuilder.create(field, "role"), CollectionProperty.class, "roles", Arrays.asList("role") ); assertProperty( PropertyBuilder.create("set", set, String.class), SetProperty.class, "set", set ); assertProperty( PropertyBuilder.create("range", range, Integer.class), RangeProperty.class, "range", range ); assertProperty( PropertyBuilder.create("equal", 1L, Long.class), EqualProperty.class, "equal", 1L ); assertProperty( PropertyBuilder.create("text", "someString", String.class.getName(), "matches()"), MatchesProperty.class, "text", ".*someString.*" ); assertProperty( PropertyBuilder.create("text", "someString", String.class.getName(), "matches((?i))"), MatchesCaseInsensitiveProperty.class, "text", "(?i).*someString.*" ); }