### Question:
CustomPageContentValidator { public void validate(File pageFolder) throws InvalidPageZipContentException { final File[] rootFiles = pageFolder.listFiles(); if (rootFiles == null) { throw new InvalidPageZipContentException( "Content not found."); } Properties pageProperties = Stream.of(rootFiles) .filter(file -> file.getName().matches(PAGE_PROPERTIES)) .findFirst() .map(this::loadProperties) .orElseThrow(() -> new InvalidPageZipContentException(String.format("%s descriptor is missing.",PAGE_PROPERTIES))); String contentType = pageProperties.getProperty(CustomPageService.PROPERTY_CONTENT_TYPE); Optional<File> resouresFolder = Stream.of(rootFiles) .filter(file -> file.getName().matches(CustomPageService.RESOURCES_PROPERTY)) .findFirst(); if (Objects.equals(contentType, ContentType.THEME)) { if (!resouresFolder.filter(resources -> new File(resources, THEME_CSS).exists()).isPresent()) { throw new InvalidPageZipContentException(String.format("%s is missing.",THEME_CSS)); } } else if (!Objects.equals(contentType, ContentType.API_EXTENSION)) { if (Stream.of(rootFiles) .noneMatch(file -> file.getName().matches(INDEX_HTML) || file.getName().matches(INDEX_GROOVY)) && !resouresFolder.filter(resources -> new File(resources, INDEX_HTML).exists() || new File(resources, INDEX_GROOVY).exists()).isPresent()) { throw new InvalidPageZipContentException(String.format("%s or %s is missing.",INDEX_HTML,INDEX_GROOVY)); } } }  void validate(File pageFolder);  }### Answer:
@Test public void zip_with_index_in_resources_should_be_valid() throws Exception { final File zipFileResource = new File(getClass().getResource("/pageWithIndexInResources.zip").toURI()); UnzipUtil.unzip(zipFileResource, new File("target" + File.separator + "pageWithIndexInResources").getPath(), false); final File unzipFolder = new File("target" + File.separator + "pageWithIndexInResources"); customPageContentValidator.validate(unzipFolder); }
@Test public void should_throw_exception_when_theme_css_not_found() throws Exception { final File invalidThemePage = new File(getClass().getResource("/invalidThemePage").toURI()); expectedException.expect(InvalidPageZipContentException.class); expectedException.expectMessage("theme.css is missing."); customPageContentValidator.validate(invalidThemePage); }
@Test public void should_throw_exception_when_page_properties_not_found() throws Exception { final File invalidCustomPage = new File(getClass().getResource("/invalidCustomPage").toURI()); expectedException.expect(InvalidPageZipContentException.class); expectedException.expectMessage("page.properties descriptor is missing."); customPageContentValidator.validate(invalidCustomPage); }
@Test public void should_throw_exception_when_index_not_found() throws Exception { final File invalidFormPage = new File(getClass().getResource("/invalidFormPage").toURI()); expectedException.expect(InvalidPageZipContentException.class); expectedException.expectMessage("index.html or Index.groovy is missing."); customPageContentValidator.validate(invalidFormPage); }