ReferencedListIterator extends AbstractListIterator { @Override Axiom<NamedResource> nextAxiom() { final NamedResource value = nextValue(); final NamedResource node = NamedResource.create(currentNode.getURI()); return new AxiomImpl<>(node, hasContentAssertion, new Value<>(value)); } ReferencedListIterator(ReferencedListDescriptor descriptor, StorageConnector connector);   }
@Test public void nextThrowsIntegrityConstraintViolationExceptionWhenNodeHasMultipleContentValues() { final List<URI> list = generateList(); final int index = Generator.randomInt(list.size()); final Resource node = testUtil.getReferencedListNodes().get(index); when(connectorMock.find(node, HAS_CONTENT, null, null)).thenReturn(Arrays.asList( createStatement(node, HAS_CONTENT, createResource(Generator.generateUri().toString())), createStatement(node, HAS_CONTENT, createResource(list.get(index).toString())) )); final ReferencedListIterator iterator = iterator(); thrown.expect(IntegrityConstraintViolatedException.class); thrown.expectMessage("Encountered multiple content values of list node " + node.getURI()); while (iterator.hasNext()) { iterator.nextAxiom(); } }
@Test public void nextThrowsIntegrityConstraintViolationExceptionWhenNodeHasNoContent() { final List<URI> list = generateList(); final int index = Generator.randomInt(list.size()); final Resource node = testUtil.getReferencedListNodes().get(index); when(connectorMock.find(node, HAS_CONTENT, null, null)).thenReturn(Collections.emptyList()); final ReferencedListIterator iterator = iterator(); thrown.expect(IntegrityConstraintViolatedException.class); thrown.expectMessage("No content found for list node " + node.getURI()); while (iterator.hasNext()) { iterator.nextAxiom(); } }
@Test public void nextReturnsFirstListElement() { final List<URI> list = generateList(); final AbstractListIterator iterator = iterator(); assertTrue(iterator.hasNext()); final Axiom<NamedResource> head = iterator.nextAxiom(); assertNotNull(head); assertEquals(descriptor(null).getNodeContent(), head.getAssertion()); assertEquals(NamedResource.create(list.get(0)), head.getValue().getValue()); }
@Test public void nextThrowsListProcessingExceptionWhenNodeIsLiteral() { generateList(); when(connectorMock.find(RESOURCE, HAS_LIST, null, null)).thenReturn( Collections.singletonList(createStatement(RESOURCE, HAS_LIST, createTypedLiteral(117)))); final ReferencedListIterator iterator = iterator(); thrown.expect(ListProcessingException.class); thrown.expectMessage("Expected successor of node " + RESOURCE + " to be a named resource."); while (iterator.hasNext()) { iterator.nextAxiom(); } }