@Test
public void testMultipleAddAndRemove() throws MalformedURLException, URISyntaxException {
String field = "urn:the.field:used.for.this.Test";
ValueFactory vf = getValueFactory();
Representation rep = createRepresentation(null);
Reference ref = vf.createReference("http://www.test.org/test");
Text text = vf.createText("test", "en");
Integer i = 42;
Double d = Math.PI;
URI uri = new URI("http://www.test.org/uriTest");
URL url = new URL("http://www.test.org/urlTest");
String[] textAsArray = new String[] {"Test text as Array", "en"};
Collection<Object> values = Arrays.asList(ref, text, i, d);
Collection<Object> convertedValues = Arrays.asList((Object) url, uri, textAsArray);
Collection<Object> allValues = Arrays.asList(ref, text, i, d, uri, url, textAsArray);
// test adding of collections
rep.add(field, values);
assertTrue(asCollection(rep.get(field)).size() == 4);
rep.remove(field, values);
assertFalse(rep.get(field).hasNext());
// test adding of Iterators
rep.add(field, values.iterator());
assertTrue(asCollection(rep.get(field)).size() == 4);
rep.remove(field, values.iterator());
assertFalse(rep.get(field).hasNext());
// test adding of Enumerations
Vector<Object> v = new Vector<Object>(values);
rep.add(field, v.elements());
assertTrue(asCollection(rep.get(field)).size() == 4);
rep.remove(field, v.elements());
assertFalse(rep.get(field).hasNext());
// test adding and removing elements that need to be converted
// only for collections this time -> want to test only converting is
// applied for both add and remove
rep.add(field, convertedValues);
assertTrue(asCollection(rep.get(field)).size() == 3);
rep.remove(field, convertedValues);
assertFalse(rep.get(field).hasNext());
// a final test to ensure, that remove does not only delete all values
rep.add(field, allValues);
assertTrue(asCollection(rep.get(field)).size() == 7);
rep.remove(field, convertedValues);
assertTrue(asCollection(rep.get(field)).size() == 4);
}