@Test
public void testMergeReferences() {

	Reference r1 = ReferenceBuilder.newInstance().withPropertyValue(P1, Q1)
			.withPropertyValue(P2, Q2).build();
	Reference r2 = ReferenceBuilder.newInstance().withPropertyValue(P1, Q1)
			.build();
	Reference r3 = ReferenceBuilder.newInstance().withPropertyValue(P2, Q2)
			.build();
	Reference r4 = ReferenceBuilder.newInstance().withPropertyValue(P2, Q2)
			.withPropertyValue(P1, Q1).build();
	Statement s1 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withReference(r1).withReference(r2)
			.withId("ID-s1").build();
	Statement s2 = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withReference(r3).withReference(r4).build();
	ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1)
			.withStatement(s1).build();
	StatementUpdate su = new StatementUpdate(currentDocument,
			Collections.singletonList(s2), Collections.emptyList());
	Statement s1merged = StatementBuilder.forSubjectAndProperty(Q1, P1)
			.withValue(Q1).withReference(r1).withReference(r2)
			.withReference(r3).withId("ID-s1").build();
	assertEquals(0, su.toDelete.size());
	assertEquals(1, su.toKeep.size());
	assertTrue(su.toKeep.containsKey(P1));
	assertEquals(1, su.toKeep.get(P1).size());
	assertEquals(s1merged, su.toKeep.get(P1).get(0).statement);
	assertTrue(su.toKeep.get(P1).get(0).write);
}