@Test public void map_emptyMD() { final String title = "ghfgjhk"; final String filePath = "iouyi"; final String contentHtml = "dsafg"; final String expectedBody = "<h1>Cdfghjhkj</h1>"; final Document contentDocument = mock(Document.class); final Elements markdownElements = mock(Elements.class); final Element markdownElement = mock(Element.class); when(githubGateway.getContentsAsHtml(OWNER, REPO, BRANCH, filePath)).thenReturn(contentHtml); when(jsoup.parse(contentHtml)).thenReturn(contentDocument); when(contentDocument.select(".markdown-body")).thenReturn(markdownElements); when(markdownElements.isEmpty()).thenReturn(true); doThrow(new IndexOutOfBoundsException()).when(markdownElements).get(0); final FaqItemDto result = mapper.map(Faq.builder().title(title).filePath(filePath).build()); assertThat(result).isNull(); }
@Override public FaqItemDto map(final Faq faq) { if (faq == null) { return null; } try { final Document document = jsoup.parse(githubGateway.getContentsAsHtml(owner, repo, branch, faq.getFilePath())); final Elements markDownBody = document.select(".markdown-body"); if (!markDownBody.isEmpty()) { final String body = markDownBody.get(0).html(); return FaqItemDto.builder() .title(faq.getTitle()) .body(body) .build(); } else { return null; } } catch (Exception e) { throw new RuntimeException("Something went wrong during the mapping of FaqItem '" + faq.getTitle() + "'", e); } }
FaqItemDtoMapper implements BaseMapper<Faq, FaqItemDto> { @Override public FaqItemDto map(final Faq faq) { if (faq == null) { return null; } try { final Document document = jsoup.parse(githubGateway.getContentsAsHtml(owner, repo, branch, faq.getFilePath())); final Elements markDownBody = document.select(".markdown-body"); if (!markDownBody.isEmpty()) { final String body = markDownBody.get(0).html(); return FaqItemDto.builder() .title(faq.getTitle()) .body(body) .build(); } else { return null; } } catch (Exception e) { throw new RuntimeException("Something went wrong during the mapping of FaqItem '" + faq.getTitle() + "'", e); } } }
FaqItemDtoMapper implements BaseMapper<Faq, FaqItemDto> { @Override public FaqItemDto map(final Faq faq) { if (faq == null) { return null; } try { final Document document = jsoup.parse(githubGateway.getContentsAsHtml(owner, repo, branch, faq.getFilePath())); final Elements markDownBody = document.select(".markdown-body"); if (!markDownBody.isEmpty()) { final String body = markDownBody.get(0).html(); return FaqItemDto.builder() .title(faq.getTitle()) .body(body) .build(); } else { return null; } } catch (Exception e) { throw new RuntimeException("Something went wrong during the mapping of FaqItem '" + faq.getTitle() + "'", e); } } FaqItemDtoMapper(final GithubGateway githubGateway,
                            @Value("${io.fundrequest.faq.owner:FundRequest}") final String owner,
                            @Value("${io.fundrequest.faq.repo:FAQ}") final String repo,
                            @Value("${io.fundrequest.faq.branch:master}") final String branch,
                            final JsoupSpringWrapper jsoup); }
FaqItemDtoMapper implements BaseMapper<Faq, FaqItemDto> { @Override public FaqItemDto map(final Faq faq) { if (faq == null) { return null; } try { final Document document = jsoup.parse(githubGateway.getContentsAsHtml(owner, repo, branch, faq.getFilePath())); final Elements markDownBody = document.select(".markdown-body"); if (!markDownBody.isEmpty()) { final String body = markDownBody.get(0).html(); return FaqItemDto.builder() .title(faq.getTitle()) .body(body) .build(); } else { return null; } } catch (Exception e) { throw new RuntimeException("Something went wrong during the mapping of FaqItem '" + faq.getTitle() + "'", e); } } FaqItemDtoMapper(final GithubGateway githubGateway,
                            @Value("${io.fundrequest.faq.owner:FundRequest}") final String owner,
                            @Value("${io.fundrequest.faq.repo:FAQ}") final String repo,
                            @Value("${io.fundrequest.faq.branch:master}") final String branch,
                            final JsoupSpringWrapper jsoup); @Override FaqItemDto map(final Faq faq); }
FaqItemDtoMapper implements BaseMapper<Faq, FaqItemDto> { @Override public FaqItemDto map(final Faq faq) { if (faq == null) { return null; } try { final Document document = jsoup.parse(githubGateway.getContentsAsHtml(owner, repo, branch, faq.getFilePath())); final Elements markDownBody = document.select(".markdown-body"); if (!markDownBody.isEmpty()) { final String body = markDownBody.get(0).html(); return FaqItemDto.builder() .title(faq.getTitle()) .body(body) .build(); } else { return null; } } catch (Exception e) { throw new RuntimeException("Something went wrong during the mapping of FaqItem '" + faq.getTitle() + "'", e); } } FaqItemDtoMapper(final GithubGateway githubGateway,
                            @Value("${io.fundrequest.faq.owner:FundRequest}") final String owner,
                            @Value("${io.fundrequest.faq.repo:FAQ}") final String repo,
                            @Value("${io.fundrequest.faq.branch:master}") final String branch,
                            final JsoupSpringWrapper jsoup); @Override FaqItemDto map(final Faq faq);  }