@Test public void getDomainsShouldContainDetectedDomainsAndIpsOfAddedDomains() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(true)); String added = "added.tld"; String detected = "detected.tld"; String detectedIp1 = "148.25.32.1"; String detectedIp2 = "148.25.32.2"; when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1")); when(dnsService.getHostName(any(InetAddress.class))).thenReturn(detected); InetAddress detectedAddress1 = mock(InetAddress.class); InetAddress detectedAddress2 = mock(InetAddress.class); when(detectedAddress1.getHostAddress()).thenReturn(detectedIp1); when(detectedAddress2.getHostAddress()).thenReturn(detectedIp2); when(dnsService.getAllByName(detected)).thenReturn(ImmutableList.of(detectedAddress1)); when(dnsService.getAllByName(added)).thenReturn(ImmutableList.of(detectedAddress2)); domainList.addDomain(Domain.of(added)); assertThat(domainList.getDomains()) .extracting(Domain::name) .contains(detected, detectedIp1, added, detectedIp2); }
@Test public void containsDomainShouldReturnTrueWhenDomainIsContained() throws Exception { Domain domain = Domain.of("added.tld"); domainList.addDomain(domain); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false)); assertThat(domainList.containsDomain(domain)).isTrue(); }
@Test public void setDefaultDomainShouldNotFailWhenDomainContained() throws Exception { Domain expectedDefaultDomain = Domain.of("myDomain.org"); domainList.addDomain(expectedDefaultDomain); domainList.configureDefaultDomain(expectedDefaultDomain); assertThat(domainList.getDomainListInternal()).contains(expectedDefaultDomain); }
@Test public void getDomainsShouldListAddedDomain() throws Exception { Domain defaultDomain = Domain.of("default.tld"); Domain domain = Domain.of("added.tld"); domainList.addDomain(domain); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(defaultDomain)); assertThat(domainList.getDomains()).containsOnly(domain, defaultDomain); }