ContextFileWorker { protected static Node getRecentPresentationsNode(final Document document) { Node recentPresentationsNode; final NodeList list = document.getElementsByTagName(RECENT_PRESENTATIONS_TAG); if (list != null && list.getLength() > 0) { recentPresentationsNode = list.item(0); } else { recentPresentationsNode = document.createElement(RECENT_PRESENTATIONS_TAG); getRootNode(document).appendChild(recentPresentationsNode); } return recentPresentationsNode; } 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 getRecentPresentationsNode() throws Exception { final String xml = "<slideshowfx><recentPresentations></recentPresentations></slideshowfx>"; final Document document = createDocumentFromString(xml); final Node recentPresentationsNode = ContextFileWorker.getRecentPresentationsNode(document); assertNotNull(recentPresentationsNode); assertEquals(RECENT_PRESENTATIONS_TAG, recentPresentationsNode.getNodeName()); }
@Test public void tryToGetRecentPresentationsNodeWhenMissing() throws Exception { final String xml = "<slideshowfx></slideshowfx>"; final Document document = createDocumentFromString(xml); final Node recentPresentationsNode = ContextFileWorker.getRecentPresentationsNode(document); assertNotNull(recentPresentationsNode); assertEquals(RECENT_PRESENTATIONS_TAG, recentPresentationsNode.getNodeName()); }