package com.google.sps;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.IOException;
import com.google.sps.data.GeoService;
import java.net.URL;
import com.google.gson.JsonObject;
import java.io.RandomAccessFile;

@RunWith(JUnit4.class)
public final class GeoTest {
  GeoService geoService = new GeoService();

  @Test
  public void readUrlTest() throws IOException {
    String actual =
        geoService.readUrl(
            new URL(
                "https://pkgstore.datahub.io/core/country-list/data_json/data/8c458f2d15d9f2119654b29ede6e45b8/data_json.json"));
    RandomAccessFile file =
        new RandomAccessFile("src/test/java/com/google/sps/CountryJson.txt", "r");
    String expected = file.readLine();
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void getUserCountryTest() throws IOException {
    String expected = "US";
    JsonObject testCoords = new JsonObject();
    testCoords.addProperty("lat", "40.7128");
    testCoords.addProperty("lng", "-74.0060");
    String actual = geoService.getUserCountry(testCoords);
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void getUserCountryTestForeign() throws IOException {
    String expected = "FR";
    JsonObject testCoords = new JsonObject();
    testCoords.addProperty("lat", "48.8566");
    testCoords.addProperty("lng", "2.3522");
    String actual = geoService.getUserCountry(testCoords);
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void formulateRSSFeedQuery() {
    String expected = "US";
    String actual = geoService.formulateRSSFeedQuery("US");
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void formulateRSSFeedQueryUnvalidCountry() {
    String expected = "global";
    String actual = geoService.formulateRSSFeedQuery("CN");
    Assert.assertEquals(expected, actual);
  }
}

@@ -224,43 +224,8 @@
 RL;%0A
-import com.google.gson.JsonObject;%0A
 impo
@@ -809,689 +809,8 @@
  %7D%0A%0A
-  @Test%0A  public void getUserCountryTest() throws IOException %7B%0A    String expected = %22US%22;%0A    JsonObject testCoords = new JsonObject();%0A    testCoords.addProperty(%22lat%22, %2240.7128%22);%0A    testCoords.addProperty(%22lng%22, %22-74.0060%22);%0A    String actual = geoService.getUserCountry(testCoords);%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A  @Test%0A  public void getUserCountryTestForeign() throws IOException %7B%0A    String expected = %22FR%22;%0A    JsonObject testCoords = new JsonObject();%0A    testCoords.addProperty(%22lat%22, %2248.8566%22);%0A    testCoords.addProperty(%22lng%22, %222.3522%22);%0A    String actual = geoService.getUserCountry(testCoords);%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A
   @T

Remove tests that require credentials