SimpleListIterator extends AbstractListIterator { @Override Axiom<NamedResource> nextAxiom() { final NamedResource subject = NamedResource.create(currentNode.getURI()); final Assertion assertion = Assertion .createObjectPropertyAssertion(URI.create(first() ? hasListProperty.getURI() : hasNextProperty.getURI()), false); final NamedResource value = nextValue(); return new AxiomImpl<>(subject, assertion, new Value<>(value)); } SimpleListIterator(SimpleListDescriptor descriptor, StorageConnector connector);   }
@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(NamedResource.create(RESOURCE.getURI()), head.getSubject()); assertEquals(Assertion.createObjectPropertyAssertion(URI.create(HAS_LIST.getURI()), false), head.getAssertion()); assertEquals(NamedResource.create(list.get(0)), head.getValue().getValue()); }
@Test public void nextThrowsListProcessingExceptionWhenNodeIsLiteral() { final List<URI> list = generateList(); final String nodeUri = list.get(list.size() - 1).toString(); when(connectorMock.find(createResource(nodeUri), HAS_NEXT, null, null)).thenReturn( Collections.singletonList(createStatement(createResource(nodeUri), HAS_NEXT, createTypedLiteral(117)))); final SimpleListIterator iterator = new SimpleListIterator(descriptor(null), connectorMock); thrown.expect(ListProcessingException.class); thrown.expectMessage("Expected successor of node " + nodeUri + " to be a named resource."); while (iterator.hasNext()) { iterator.nextAxiom(); } }
@Test public void removeWithoutReconnectRemovesLastElementInList() { final List<URI> list = generateList(); final SimpleListIterator iterator = new SimpleListIterator(descriptor(null), connectorMock); while (iterator.hasNext()) { iterator.nextAxiom(); } iterator.removeWithoutReconnect(); verify(connectorMock).remove(createResource(list.get(list.size() - 2).toString()), HAS_NEXT, createResource(list.get(list.size() - 1).toString()), null); }