* correct implementation of the {@link Text#equals(Object)} method
*/
@Test
public void testStringArrayToTextConversion() {
String field = "urn:the.field:used.for.this.Test";
ValueFactory vf = getValueFactory();
Representation rep = createRepresentation(null);
// 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());