ContextFileWorker { protected static Node findRecentPresentationNodeFromID(final Document document, final RecentPresentation recentPresentation) throws ContextFileException { final StringBuilder expression = new StringBuilder("/").append(ROOT_TAG) .append("/").append(RECENT_PRESENTATIONS_TAG) .append("/").append(RECENT_PRESENTATION_TAG) .append("[").append(ID_TAG).append(" = '").append(recentPresentation.getId()) .append("'][1]"); try { return (Node) xpath().evaluate(expression.toString(), document.getDocumentElement(), NODE); } catch (XPathExpressionException e) { throw new ContextFileException(e); } } private  ContextFileWorker(); static Set<RecentPresentation> readRecentPresentationFromFile(final File contextFile); static void saveRecentPresentationToFile(final File contextFile, final RecentPresentation recentPresentation); static void updateRecentPresentationInFile(final File contextFile, final RecentPresentation recentPresentation); static boolean recentPresentationAlreadyPresent(final File contextFile, final RecentPresentation recentPresentation); static Set<RecentPresentation> purgeRecentPresentations(final InputStream input, final OutputStream output, final long numberOfRecentPresentationsToKeep);  }
@Test public void findExistingRecentPresentation() throws Exception { final RecentPresentation recentPresentation1 = new RecentPresentation("presentation1.sfx", LocalDateTime.now()); final RecentPresentation recentPresentation2 = new RecentPresentation("presentation2.sfx", recentPresentation1.getOpenedDateTime().plusDays(2)); final String xml = this.createXmlStringFromRecentPresentations(recentPresentation1, recentPresentation2); final Document document = createDocumentFromString(xml); Node node = ContextFileWorker.findRecentPresentationNodeFromID(document, recentPresentation1); assertRecentPresentationNode(node, recentPresentation1); node = ContextFileWorker.findRecentPresentationNodeFromID(document, recentPresentation2); assertRecentPresentationNode(node, recentPresentation2); }
@Test public void findRecentPresentationWhenMissing() throws Exception { final RecentPresentation recentPresentation1 = new RecentPresentation("presentation1.sfx", LocalDateTime.now()); final RecentPresentation recentPresentation2 = new RecentPresentation("presentation2.sfx", recentPresentation1.getOpenedDateTime().plusDays(2)); final RecentPresentation recentPresentation3 = new RecentPresentation("presentation3.sfx", recentPresentation2.getOpenedDateTime().plusDays(2)); final String xml = this.createXmlStringFromRecentPresentations(recentPresentation1, recentPresentation2); final Document document = createDocumentFromString(xml); Node node = ContextFileWorker.findRecentPresentationNodeFromID(document, recentPresentation3); assertNull(node); }