@Test public void testReadingIncorrectFile() throws Exception { assertThat(LibrarySpecificationReader.readSpecification(null)).isNotPresent(); final File folder = new File(tempDir, "folder"); folder.mkdir(); assertThat(LibrarySpecificationReader.readSpecification(folder)).isNotPresent(); assertThat(LibrarySpecificationReader.readSpecification(new File("not_existing_file"))).isNotPresent(); final File file = new File(tempDir, "file"); file.createNewFile(); assertThat(LibrarySpecificationReader.readSpecification(file)).isNotPresent(); }
public static Optional<LibrarySpecification> readSpecification(final File file) { if (file == null || !file.isFile() || !file.exists()) { return Optional.empty(); } try { final JAXBContext jaxbContext = JAXBContext.newInstance(LibrarySpecification.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final LibrarySpecification spec = (LibrarySpecification) jaxbUnmarshaller.unmarshal(file); if (spec.getSpecificationVersion() >= 2) { spec.getKeywordsStream() .filter(kwSpec -> kwSpec.getDeprecatedState() == null) .forEach(kwSpec -> kwSpec.setDeprecated(false)); } return Optional.ofNullable(spec); } catch (final JAXBException e) { return Optional.empty(); } }
LibrarySpecificationReader { public static Optional<LibrarySpecification> readSpecification(final File file) { if (file == null || !file.isFile() || !file.exists()) { return Optional.empty(); } try { final JAXBContext jaxbContext = JAXBContext.newInstance(LibrarySpecification.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final LibrarySpecification spec = (LibrarySpecification) jaxbUnmarshaller.unmarshal(file); if (spec.getSpecificationVersion() >= 2) { spec.getKeywordsStream() .filter(kwSpec -> kwSpec.getDeprecatedState() == null) .forEach(kwSpec -> kwSpec.setDeprecated(false)); } return Optional.ofNullable(spec); } catch (final JAXBException e) { return Optional.empty(); } } }
LibrarySpecificationReader { public static Optional<LibrarySpecification> readSpecification(final File file) { if (file == null || !file.isFile() || !file.exists()) { return Optional.empty(); } try { final JAXBContext jaxbContext = JAXBContext.newInstance(LibrarySpecification.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final LibrarySpecification spec = (LibrarySpecification) jaxbUnmarshaller.unmarshal(file); if (spec.getSpecificationVersion() >= 2) { spec.getKeywordsStream() .filter(kwSpec -> kwSpec.getDeprecatedState() == null) .forEach(kwSpec -> kwSpec.setDeprecated(false)); } return Optional.ofNullable(spec); } catch (final JAXBException e) { return Optional.empty(); } }  }
LibrarySpecificationReader { public static Optional<LibrarySpecification> readSpecification(final File file) { if (file == null || !file.isFile() || !file.exists()) { return Optional.empty(); } try { final JAXBContext jaxbContext = JAXBContext.newInstance(LibrarySpecification.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final LibrarySpecification spec = (LibrarySpecification) jaxbUnmarshaller.unmarshal(file); if (spec.getSpecificationVersion() >= 2) { spec.getKeywordsStream() .filter(kwSpec -> kwSpec.getDeprecatedState() == null) .forEach(kwSpec -> kwSpec.setDeprecated(false)); } return Optional.ofNullable(spec); } catch (final JAXBException e) { return Optional.empty(); } }  static Optional<LibrarySpecification> readSpecification(final File file); }
LibrarySpecificationReader { public static Optional<LibrarySpecification> readSpecification(final File file) { if (file == null || !file.isFile() || !file.exists()) { return Optional.empty(); } try { final JAXBContext jaxbContext = JAXBContext.newInstance(LibrarySpecification.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final LibrarySpecification spec = (LibrarySpecification) jaxbUnmarshaller.unmarshal(file); if (spec.getSpecificationVersion() >= 2) { spec.getKeywordsStream() .filter(kwSpec -> kwSpec.getDeprecatedState() == null) .forEach(kwSpec -> kwSpec.setDeprecated(false)); } return Optional.ofNullable(spec); } catch (final JAXBException e) { return Optional.empty(); } }  static Optional<LibrarySpecification> readSpecification(final File file);  }