ContextFileWorker { protected static RecentPresentation buildRecentPresentationFromNode(final Node node) { RecentPresentation recentPresentation = null; LocalDateTime openedDateTime = null; String path = null; final NodeList children = node.getChildNodes(); int index = 0; while (index < children.getLength() && (openedDateTime == null || path == null)) { final Node child = children.item(index++); switch (child.getNodeName()) { case OPENED_DATE_TIME_TAG: openedDateTime = LocalDateTime.parse(child.getTextContent()); break; case FILE_TAG: path = child.getTextContent(); break; default: LOGGER.fine(child.getNodeName() + " not supported"); } } if (openedDateTime != null && path != null) { recentPresentation = new RecentPresentation(path, openedDateTime); } return recentPresentation; } 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 createRecentPresentationFromNode() { final LocalDateTime date = LocalDateTime.now(); final Path path = Paths.get("presentation.sfx"); final String normalizedPath = path.toAbsolutePath().toString().replaceAll("\\\\", "/"); final String id = Base64.getEncoder().encodeToString(normalizedPath.getBytes(UTF_8)); final Node node = createRecentPresentationNode(createIdNode(id), createFileNode(path.toAbsolutePath().toString()), createOpenedDateTimeNode(date)); final RecentPresentation recentPresentation = ContextFileWorker.buildRecentPresentationFromNode(node); assertNotNull(recentPresentation); assertEquals(normalizedPath, recentPresentation.getNormalizedPath()); assertEquals(date, recentPresentation.getOpenedDateTime()); }
@Test public void createRecentPresentationFromNodeWithoutPath() { final LocalDateTime date = LocalDateTime.now(); final Node node = createRecentPresentationNode(createOpenedDateTimeNode(date)); final RecentPresentation recentPresentation = ContextFileWorker.buildRecentPresentationFromNode(node); assertNull(recentPresentation); }
@Test public void createRecentPresentationFromNodeWithoutOpenedDate() { final String path = "/presentation.sfx"; final Node node = createRecentPresentationNode(createFileNode(path)); final RecentPresentation recentPresentation = ContextFileWorker.buildRecentPresentationFromNode(node); assertNull(recentPresentation); }
@Test public void createRecentPresentationFromNodeWithoutChildren() { final Node node = createRecentPresentationNode(); final RecentPresentation recentPresentation = ContextFileWorker.buildRecentPresentationFromNode(node); assertNull(recentPresentation); }