### Question:
PropertySettingStrategy { public void setProperty( PropertyContainer entity, String key, Object value ) throws PropertyValueException { if ( value instanceof Collection ) { if ( ((Collection<?>) value).size() == 0 ) { Object currentValue = entity.getProperty( key, null ); if ( currentValue != null && currentValue.getClass().isArray() ) { if ( Array.getLength( currentValue ) == 0 ) { return; } value = emptyArrayOfType( currentValue.getClass().getComponentType() ); } else { throw new PropertyValueException( "Unable to set property '" + key + "' to an empty array, " + "because, since there are no values of any type in it, " + "and no pre-existing collection to infer type from, it is not possible " + "to determine what type of array to store." ); } } else { value = convertToNativeArray( (Collection<?>) value ); } } try ( Transaction tx = db.beginTx() ) { entity.setProperty( key, value ); tx.success(); } catch ( IllegalArgumentException e ) { throw new PropertyValueException( "Could not set property \"" + key + "\", unsupported type: " + value ); } } PropertySettingStrategy( GraphDatabaseAPI db ); void setAllProperties( PropertyContainer entity, Map<String, Object> properties ); void setProperties( PropertyContainer entity, Map<String, Object> properties ); void setProperty( PropertyContainer entity, String key, Object value ); Object convert( Object value ); static Object convertToNativeArray( Collection<?> collection );  }### Answer:
@Test public void shouldSetSingleProperty() throws Exception { Node node = db.createNode(); propSetter.setProperty( node, "name", "bob" ); assertThat( node.getProperty( "name" ), is("bob")); }
@Test public void shouldNotFailSettingEmptyArrayIfEntityAlreadyHasAnEmptyArrayAsValue() throws Exception { Node node = db.createNode(); node.setProperty( "arr", new String[]{} ); propSetter.setProperty( node, "arr", new ArrayList<>() ); assertThat( node.getProperty( "arr" ), is(new String[]{})); }
@Test( expected = PropertyValueException.class ) public void shouldThrowPropertyErrorWhenSettingEmptyArrayOnEntityWithNoPreExistingProperty() throws Exception { Node node = db.createNode(); propSetter.setProperty( node, "arr", new ArrayList<>() ); }
@Test( expected = PropertyValueException.class ) public void shouldThrowPropertyErrorWhenSettingEmptyArrayOnEntityWithNoPreExistingEmptyArray() throws Exception { Node node = db.createNode(); node.setProperty( "arr", "hello" ); propSetter.setProperty( node, "arr", new ArrayList<>() ); }
@Test public void shouldUseOriginalTypeWhenSettingEmptyArrayIfEntityAlreadyHasACollection() throws Exception { Node node = db.createNode(); node.setProperty( "arr", new String[]{"a","b"} ); propSetter.setProperty( node, "arr", new ArrayList<>() ); assertThat( node.getProperty( "arr" ), is(new String[]{})); }