private static void testSetIntoCollection(final boolean conversion) {
final String text1 = "An other title";
final String text2 = "Yet an other title";
final InternationalString title1 = new SimpleInternationalString(text1);
final InternationalString title2 = new SimpleInternationalString(text2);
final DefaultCitation instance = new DefaultCitation("Ignored title");
final PropertyAccessor accessor = createPropertyAccessor();
final int index = accessor.indexOf("alternateTitles", true);
// Insert the first value. Old collection shall be empty.
Object oldValue = accessor.set(index, instance, conversion ? text1 : title1, RETURN_PREVIOUS);
assertInstanceOf("alternateTitles", Collection.class, oldValue);
assertTrue("alternateTitles", ((Collection<?>) oldValue).isEmpty());
// Insert the second value. Old collection shall contain the first value.
oldValue = accessor.set(index, instance, conversion ? text2 : title2, RETURN_PREVIOUS);
assertInstanceOf("alternateTitles", Collection.class, oldValue);
oldValue = getSingleton((Collection<?>) oldValue);
assertSame("alternateTitles", text1, oldValue.toString());
if (!conversion) {
assertSame("InternationalString should have been stored as-is.", title1, oldValue);
}
// Check final collection content.
final List<InternationalString> expected = Arrays.asList(title1, title2);
assertEquals("alternateTitles", expected, accessor.get(index, instance));
assertEquals("title", "Ignored title", instance.getTitle().toString());
}