@Test
public void urlCheckerToSetStatus() throws Exception {

    Element mdAsXml = getMdAsXml();
    AbstractMetadata md = insertMetadataInDb(mdAsXml);
    UrlAnalyzer toTest = createToTest();
    UrlChecker mockUrlChecker = mock(UrlChecker.class);
    toTest.urlChecker = mockUrlChecker;
    Mockito.when(mockUrlChecker.getUrlStatus(eq("http://apps.titellus.net/geonetwork/srv/api/records/da165110-88fd-11da-a88f-000d939bc5d8/attachments/thumbnail_s.gif"))).thenReturn(new LinkStatus().setStatusValue("200").setStatusInfo("OK").setFailing(false));
    Mockito.when(mockUrlChecker.getUrlStatus(eq("http://apps.titellus.net/geonetwork/srv/api/records/da165110-88fd-11da-a88f-000d939bc5d8/attachments/thumbnail.gif"))).thenReturn(new LinkStatus().setStatusValue("200").setStatusInfo("OK").setFailing(false));
    Mockito.when(mockUrlChecker.getUrlStatus(eq("ftp://mon-site.mondomaine/mon-repertoire"))).thenReturn(new LinkStatus().setStatusValue("406").setStatusInfo("Le serveur HTCPCP ne peut pas infuser du café pour différentes raisons, la réponse devrait indiquer une liste de types de café possibles.").setFailing(true));
    Mockito.when(mockUrlChecker.getUrlStatus(eq("HTTPS://acme.de/"))).thenReturn(new LinkStatus().setStatusValue("418").setStatusInfo("I am teapot").setFailing(true));
    Mockito.when(mockUrlChecker.getUrlStatus(contains("aquastat"))).thenReturn(new LinkStatus().setStatusValue("418").setStatusInfo("I am teapot").setFailing(true));
    Mockito.when(mockUrlChecker.getUrlStatus(contains("data.fao"))).thenReturn(new LinkStatus().setStatusValue("418").setStatusInfo("I am teapot").setFailing(true));
    toTest.processMetadata(mdAsXml, md);
    SimpleJpaRepository statusRepository = new SimpleJpaRepository<LinkStatus, Integer>(LinkStatus.class, entityManager);
    assertEquals(0, statusRepository.findAll().size());
    linkRepository.findAll().stream().forEach(toTest::testLink);
    List<LinkStatus> allStatus = statusRepository.findAll();
    assertEquals(6, allStatus.size());
    assertEquals(Stream.of("200", "406", "418").collect(Collectors.toSet()),
            allStatus.stream().map(LinkStatus::getStatusValue).collect(Collectors.toSet()));
    toTest.urlChecker = mockUrlChecker;
    Mockito.when(mockUrlChecker.getUrlStatus(eq("http://apps.titellus.net/geonetwork/srv/api/records/da165110-88fd-11da-a88f-000d939bc5d8/attachments/thumbnail_s.gif"))).thenReturn(new LinkStatus().setStatusValue("200").setStatusInfo("OK").setFailing(false));
    Mockito.when(mockUrlChecker.getUrlStatus(eq("http://apps.titellus.net/geonetwork/srv/api/records/da165110-88fd-11da-a88f-000d939bc5d8/attachments/thumbnail.gif"))).thenReturn(new LinkStatus().setStatusValue("200").setStatusInfo("OK").setFailing(false));
    Mockito.when(mockUrlChecker.getUrlStatus(eq("ftp://mon-site.mondomaine/mon-repertoire"))).thenReturn(new LinkStatus().setStatusValue("200").setStatusInfo("OK").setFailing(true));
    Mockito.when(mockUrlChecker.getUrlStatus(eq("HTTPS://acme.de/"))).thenReturn(new LinkStatus().setStatusValue("200").setStatusInfo("OK").setFailing(true));
    Mockito.when(mockUrlChecker.getUrlStatus(contains("aquastat"))).thenReturn(new LinkStatus().setStatusValue("418").setStatusInfo("I am teapot").setFailing(true));
    Mockito.when(mockUrlChecker.getUrlStatus(contains("data.fao"))).thenReturn(new LinkStatus().setStatusValue("418").setStatusInfo("I am teapot").setFailing(true));
    linkRepository.findAll().stream().forEach(toTest::testLink);
    allStatus = statusRepository.findAll();
    assertEquals(12, allStatus.size());
    Map<String, Long> grouped = allStatus.stream().map(LinkStatus::getStatusValue).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    assertEquals(6L, grouped.get("200").longValue());
    assertEquals(1L,grouped.get("406").longValue());
    assertEquals(5L, grouped.get("418").longValue());
}