package com.jdig;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jdig.model.DnsEntry;
import com.jdig.model.Type;

public class DnsLookupTest {

        public static Logger logger = LoggerFactory.getLogger(DnsLookupTest.class);

        @Test
        public void shouldDigGoogleMXAtGoogleDnsServer() {
                List<DnsEntry> lookupEntries = new DnsLookup().lookup("8.8.8.8", "google.com", Type.MX);

                List<DnsEntry> expectedEntries = new ArrayList<>();
                expectedEntries.add(new DnsEntry(Type.MX, "alt3.aspmx.l.google.com.", 40));
                expectedEntries.add(new DnsEntry(Type.MX, "alt1.aspmx.l.google.com.", 20));
                expectedEntries.add(new DnsEntry(Type.MX, "aspmx.l.google.com.", 10));
                expectedEntries.add(new DnsEntry(Type.MX, "alt4.aspmx.l.google.com.", 50));
                expectedEntries.add(new DnsEntry(Type.MX, "alt2.aspmx.l.google.com.", 30));

                lookupEntries.sort((e1,e2) -> e1.getName().compareTo(e2.getName()));
                expectedEntries.sort((e1,e2) -> e1.getName().compareTo(e2.getName()));

                assertEquals(expectedEntries, lookupEntries);
        }

}

@@ -56,16 +56,59 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Aimport
@@ -146,20 +146,117 @@
 va.util.
-List
+Collections;%0Aimport java.util.Comparator;%0Aimport java.util.List;%0A%0Aimport javax.naming.NamingException
 ;%0A%0Aimpor
@@ -412,30 +412,25 @@
  Dns
-LookupTest %7B%0A%0A        
+ServiceTest %7B%0A%09%0A%09
 publ
@@ -482,22 +482,23 @@
 gger(Dns
-Lookup
+Service
 Test.cla
@@ -506,31 +506,18 @@
 s);%0A
-%0A        @Test%0A        
+%09%0A%09@Test%0A%09
 publ
@@ -565,18 +565,33 @@
 r() 
-%7B%0A        
+throws NamingException %7B%0A
     
@@ -636,35 +636,37 @@
  Dns
-Lookup().lookup(%228.8.8.8%22, 
+Service(%228.8.8.8:53%22).lookup(
 %22goo
@@ -685,25 +685,24 @@
 pe.MX);%0A
-%0A
         
         
@@ -685,32 +685,33 @@
 pe.MX);%0A        
+%0A
         List%3CDns
@@ -753,21 +753,21 @@
 ist%3C
-%3E();%0A        
+DnsEntry%3E();%0A
     
@@ -850,32 +850,24 @@
 ));%0A        
- 
-       
 expectedEntr
@@ -934,32 +934,24 @@
 ));%0A        
- 
-       
 expectedEntr
@@ -1013,32 +1013,24 @@
 ));%0A        
- 
-       
 expectedEntr
@@ -1089,32 +1089,24 @@
 om.%22, 50));%0A
-        
         expe
@@ -1190,47 +1190,150 @@
     
-        lookupEntries.sort((e1,e2) -%3E e
+Comparator%3CDnsEntry%3E nameComparator = new Comparator%3CDnsEntry%3E() %7B%0A%09%09%09@Override%0A%09%09%09public int compare(DnsEntry o1, DnsEntry o2) %7B%0A%09%09%09%09return o
 1.ge
@@ -1342,33 +1342,33 @@
 ame().compareTo(
-e
+o
 2.getName()));%0A 
@@ -1363,27 +1363,31 @@
 tName())
-)
 ;%0A
+%09%09%09%7D%0A
         
         
@@ -1378,24 +1378,27 @@
         
+%7D;%0A
         
 expected
@@ -1393,88 +1393,133 @@
     
-expectedEntries.sort((e1,e2) -%3E e1.getName().compareTo(e2.getName())
+%0A        Collections.sort(lookupEntries, nameComparator);%0A        Collections.sort(expectedEntries, nameComparator
 );%0A
-%0A
         
     
@@ -1510,24 +1510,25 @@
 r);%0A        
+%0A
         asse
@@ -1569,21 +1569,492 @@
 tries);%0A
-        
+%09%7D%0A%09%0A%09@Test%0A%09public void shouldDigAtGithubAuthoritativeServer() throws NamingException %7B%0A%09%09List%3CDnsEntry%3E lookupEntries = new DnsService(%22ns1.p16.dynect.net.%22, null, null, true, null).lookup(%22github.com%22, Type.MX);%0A%09%09assertTrue(lookupEntries.size() %3E 0);%0A%09%7D%0A%0A%09@Test(expected=NamingException.class)%0A%09public void shouldThrowExceptionWhenQueryingOnNonAuthoritativeServer() throws NamingException %7B%0A%09%09new DnsService(%228.8.8.8%22, null, null, true, null).lookup(%22google.com%22, Type.MX);%0A%09
 %7D%0A%0A%7D%0A

add simple tests for DnsService