// test conversion of String[] with language as second element
String[] textWithLang = new String[] {"Test text with language", "en"};
rep.add(field, textWithLang);
Iterator<Text> refs = rep.get(field, (String[]) null);
assertTrue(refs.hasNext());
Text test = refs.next();
assertEquals(textWithLang[1], test.getLanguage());
assertEquals(textWithLang[0], test.getText());
assertFalse(refs.hasNext());
// test multiple adds do not generate duplicate References
rep.add(field, textWithLang);
assertTrue(asCollection(rep.get(field)).size() == 1);
// test adding a equivalent reference
rep.add(field, vf.createText(textWithLang[0], textWithLang[1]));
assertTrue(asCollection(rep.get(field)).size() == 1);
// test removing
rep.remove(field, textWithLang);
assertFalse(rep.get(field).hasNext());
// test conversion of String[] with only one element (default language)
String[] textWithoutLang = new String[] {"Test text without language"};
rep.add(field, textWithoutLang);
refs = rep.get(field, (String[]) null);
assertTrue(refs.hasNext());
test = refs.next();
assertNull(test.getLanguage());
assertEquals(textWithoutLang[0], test.getText());
assertFalse(refs.hasNext());
// test multiple adds do not generate duplicate References
rep.add(field, textWithoutLang);
assertTrue(asCollection(rep.get(field)).size() == 1);
// test adding a equivalent reference
rep.add(field, vf.createText(textWithoutLang[0]));
assertTrue(asCollection(rep.get(field)).size() == 1);
// test removing
rep.remove(field, textWithoutLang);
assertFalse(rep.get(field).hasNext());
// test conversion of String[] with null as second element (default language)
String[] textWithDefaultLang = new String[] {"Test text with default language", null};
rep.add(field, textWithDefaultLang);
refs = rep.get(field, (String[]) null);
assertTrue(refs.hasNext());
test = refs.next();
assertNull(test.getLanguage());
assertEquals(textWithDefaultLang[0], test.getText());
assertFalse(refs.hasNext());
// test multiple adds do not generate duplicate References
rep.add(field, textWithDefaultLang);
assertTrue(asCollection(rep.get(field)).size() == 1);
// test adding a equivalent reference
rep.add(field, vf.createText(textWithDefaultLang[0], null));
assertTrue(asCollection(rep.get(field)).size() == 1);
// test removing
rep.remove(field, textWithDefaultLang);
assertFalse(rep.get(field).hasNext());
// finally test if additional Elements are correctly ignored
String[] ignoreAdditionalElements = new String[] {"Test if additional elements are ignored", "en",
"ignored1", "ignored2", null, "ignored4"};
String[] sameText = new String[] {"Test if additional elements are ignored", "en"};
rep.add(field, ignoreAdditionalElements);
refs = rep.get(field, (String[]) null);
assertTrue(refs.hasNext());
test = refs.next();
assertEquals(ignoreAdditionalElements[1], test.getLanguage());
assertEquals(ignoreAdditionalElements[0], test.getText());
assertFalse(refs.hasNext());
// test multiple adds do not generate duplicate References
rep.add(field, ignoreAdditionalElements);
assertTrue(asCollection(rep.get(field)).size() == 1);
// test if an Array with only the first two elements generate the same Text