JAMES-2285 Get ride of an DNS test implementation
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b259e6fd Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b259e6fd Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b259e6fd Branch: refs/heads/master Commit: b259e6fd1bc8eb50fc2dcc63ba254878132479a4 Parents: 4642814 Author: benwa <[email protected]> Authored: Sat Jan 20 17:43:06 2018 +0700 Committer: benwa <[email protected]> Committed: Tue Jan 30 15:09:47 2018 +0700 ---------------------------------------------------------------------- .../dnsservice/api/InMemoryDNSService.java | 5 +- .../library/MXHostAddressIteratorTest.java | 85 +++----------------- 2 files changed, 13 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/b259e6fd/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java ---------------------------------------------------------------------- diff --git a/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java b/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java index 11b0e4b..92fae2b 100644 --- a/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java +++ b/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java @@ -63,8 +63,9 @@ public class InMemoryDNSService implements DNSService { return this; } - public void registerRecord(String hostname, List<InetAddress> addresses, Collection<String> mxRecords, Collection<String> txtRecords) { + public InMemoryDNSService registerRecord(String hostname, List<InetAddress> addresses, Collection<String> mxRecords, Collection<String> txtRecords) { records.put(hostname, dnsRecordFor(mxRecords, txtRecords, addresses)); + return this; } public void dropRecord(String hostname) { @@ -127,7 +128,7 @@ public class InMemoryDNSService implements DNSService { .orElseThrow(() -> new UnknownHostException()); } - private static class DNSRecord { + public static class DNSRecord { final Collection<String> mxRecords; final Collection<String> txtRecords; http://git-wip-us.apache.org/repos/asf/james-project/blob/b259e6fd/server/dns-service/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java ---------------------------------------------------------------------- diff --git a/server/dns-service/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java b/server/dns-service/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java index c2aa2bb..7e6bb45 100644 --- a/server/dns-service/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java +++ b/server/dns-service/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java @@ -23,12 +23,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.Arrays; -import java.util.Collection; import org.apache.james.dnsservice.api.DNSService; -import org.apache.james.dnsservice.api.TemporaryResolutionException; +import org.apache.james.dnsservice.api.InMemoryDNSService; import org.junit.Test; import com.google.common.collect.ImmutableList; @@ -39,43 +37,15 @@ public class MXHostAddressIteratorTest { * Test case for JAMES-1251 */ @Test - public void testIteratorContainMultipleMX() { - DNSService dns = new DNSService() { + public void testIteratorContainMultipleMX() throws Exception { + InetAddress address = InetAddress.getLocalHost(); + ImmutableList<String> mxs = ImmutableList.of(address.getHostAddress()); + ImmutableList<String> noTxtRecord = ImmutableList.of(); + ImmutableList<InetAddress> addresses = ImmutableList.of(address, address); + DNSService dns = new InMemoryDNSService() + .registerRecord("localhost", addresses, mxs, noTxtRecord) + .registerRecord("localhost2", addresses, mxs, noTxtRecord); - @Override - public InetAddress getLocalHost() throws UnknownHostException { - throw new UnsupportedOperationException(); - } - - @Override - public String getHostName(InetAddress addr) { - throw new UnsupportedOperationException(); - } - - @Override - public InetAddress getByName(String host) throws UnknownHostException { - return InetAddress.getLocalHost(); - } - - /** - * Every time this method is called it will return two InetAddress instances - */ - @Override - public Collection<InetAddress> getAllByName(String host) throws UnknownHostException { - InetAddress addr = InetAddress.getLocalHost(); - return ImmutableList.of(addr, addr); - } - - @Override - public Collection<String> findTXTRecords(String hostname) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException { - throw new UnsupportedOperationException(); - } - }; MXHostAddressIterator it = new MXHostAddressIterator(Arrays.asList("localhost", "localhost2").iterator(), dns, false); for (int i = 0; i < 4; i++) { assertTrue(it.hasNext()); @@ -93,44 +63,9 @@ public class MXHostAddressIteratorTest { @Test public void testIteratorWithInvalidMX() { - DNSService dns = new DNSService() { - - @Override - public InetAddress getLocalHost() throws UnknownHostException { - throw new UnsupportedOperationException(); - } - - @Override - public String getHostName(InetAddress addr) { - throw new UnsupportedOperationException(); - } - - @Override - public InetAddress getByName(String host) throws UnknownHostException { - throw new UnknownHostException(); - } - - /** - * Every time this method is called it will return two InetAddress instances - */ - @Override - public Collection<InetAddress> getAllByName(String host) throws UnknownHostException { - throw new UnknownHostException(); - } - - @Override - public Collection<String> findTXTRecords(String hostname) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException { - throw new UnsupportedOperationException(); - } - }; // See JAMES-1271 - MXHostAddressIterator it = new MXHostAddressIterator(Arrays.asList("localhost").iterator(), dns, false); + MXHostAddressIterator it = new MXHostAddressIterator(Arrays.asList("localhost").iterator(), new InMemoryDNSService(), false); assertFalse(it.hasNext()); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
