package com.codeborne.geoip;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.*;

public class LookupServiceTest {
  LookupService lookupService;

  @Before
  public void usesProvidedDatabaseFile() throws IOException {
    lookupService = LookupService.indexCache();
  }

  @Test
  public void location1() throws IOException {
    Location location = lookupService.getLocation("217.71.44.212");
    assertEquals("EE", location.countryCode);
    assertEquals("Estonia", location.countryName);
    assertEquals("Tallinn", location.city);
    assertEquals("01", location.region);
    assertEquals(59.4339, location.latitude, 0.0001);
    assertEquals(24.728104, location.longitude, 0.000001);
  }
  
  @Test
  public void location2() throws IOException {
    Location location = lookupService.getLocation("213.172.3.234");
    assertEquals("RU", location.countryCode);
    assertEquals("Russian Federation", location.countryName);
    assertEquals(55.75, location.latitude, 0.01);
    assertEquals(37.616592, location.longitude, 0.000001);
  }

  @Test
  public void location3() throws IOException {
    Location location = lookupService.getLocation("85.117.103.134");
    assertEquals("KZ", location.countryCode);
    assertEquals("Kazakhstan", location.countryName);
    assertEquals("Almaty", location.city);
    assertEquals(43.2565, location.latitude, 0.01);
    assertEquals(76.9284, location.longitude, 0.0001);
  }

  @After
  public void tearDown() {
    if (lookupService != null)
      lookupService.close();
  }
}
@@ -72,16 +72,41 @@
 Before;%0A
+import org.junit.Ignore;%0A
 import o
@@ -1524,16 +1524,494 @@
 );%0A  %7D%0A%0A
+  @Test @Ignore(%22current implementation of geo-ip fails for this South Sudan address (it's quite new country)%22)%0A  public void location4() throws IOException %7B%0A    Location location = lookupService.getLocation(%22105.235.210.70%22);%0A    assertEquals(%22SS%22, location.countryCode);%0A    assertEquals(%22%D0%AE%D0%B6%D0%BD%D1%8B%D0%B9 %D0%A1%D1%83%D0%B4%D0%B0%D0%BD%22, location.countryName);%0A    assertEquals(%22%D0%90%D1%84%D1%80%D0%B8%D0%BA%D0%B0%22, location.city);%0A    assertEquals(4.85, location.latitude, 0.01);%0A    assertEquals(31.6, location.longitude, 0.0001);%0A  %7D%0A%0A
   @After

add South Sudan case