AutoCaptureSource { static Optional<AutoCaptureSource> newInstance(String value, SourceType type) { boolean isSupportedType = type == SourceType.DEFAULT_PATH || type == SourceType.FILE; Path path = type == SourceType.DEFAULT_PATH ? Paths.get(HoverflyConstants.DEFAULT_HOVERFLY_EXPORT_PATH).resolve(value) : Paths.get(value); if (isSupportedType && !Files.isRegularFile(path)) { return Optional.of(new AutoCaptureSource(path)); } else { return Optional.empty(); } } private  AutoCaptureSource(Path capturePath);   }
@Test void shouldReturnEmptyOptionalIfSourceTypeIsNotSupported() { Optional<AutoCaptureSource> autoCaptureSource = AutoCaptureSource.newInstance("test-service-https.json", HoverflySimulate.SourceType.CLASSPATH); assertThat(autoCaptureSource).isNotPresent(); }
@Test void shouldReturnEmptyOptionalIfSourceExists() { Optional<AutoCaptureSource> autoCaptureSource = AutoCaptureSource.newInstance("src/test/resources/test-service-https.json", HoverflySimulate.SourceType.FILE); assertThat(autoCaptureSource).isNotPresent(); }