package com.google.sps.data;

import com.google.maps.model.LatLng;
import java.util.TimeZone;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** */
@RunWith(JUnit4.class)
public final class LocationTest {
  Location location = new Location("Los Angeles");
  Location blankLocation = new Location(" ");

  @Test
  public void checkAddressField() {
    String actual = location.getAddress();
    String expected = "Los Angeles";
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkFormattedAddressField() {
    String actual = location.getAddressFormatted();
    String expected = "Los Angeles, CA, USA";
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkLatitude() {
    Double actual = location.getLat();
    Double expected = 34.05223420;
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkLongitude() {
    Double actual = location.getLng();
    Double expected = -118.24368490;
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkCoords() {
    LatLng actual = location.getCoords();
    LatLng expected = new LatLng(34.05223420, -118.24368490);
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkTimeZoneID() {
    String actual = location.getTimeZoneID();
    String expected = "America/Los_Angeles";
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkTimeZoneName() {
    String actual = location.getTimeZoneName();
    String expected = "Pacific Standard Time";
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkTimeZone() {
    TimeZone actual = location.getTimeZone();
    TimeZone expected = TimeZone.getTimeZone("America/Los_Angeles");
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkBlankAddressField() {
    String actual = blankLocation.getAddress();
    String expected = " ";
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkBlankFormattedAddressField() {
    String actual = blankLocation.getAddressFormatted();
    String expected = null;
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkBlankLatitude() {
    Double actual = blankLocation.getLat();
    Double expected = 0.0;
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkBlankLongitude() {
    Double actual = blankLocation.getLng();
    Double expected = 0.0;
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkBlankCoords() {
    LatLng actual = blankLocation.getCoords();
    LatLng expected = null;
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkBlankTimeZoneID() {
    String actual = blankLocation.getTimeZoneID();
    String expected = null;
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkBlankTimeZoneName() {
    String actual = blankLocation.getTimeZoneName();
    String expected = null;
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void checkBlankTimeZone() {
    TimeZone actual = blankLocation.getTimeZone();
    TimeZone expected = null;
    Assert.assertEquals(expected, actual);
  }
}

@@ -50,20 +50,135 @@
 aps.
-model.LatLng
+errors.ApiException;%0Aimport com.google.maps.model.LatLng;%0Aimport com.google.sps.utils.LocationUtils;%0Aimport java.io.IOException
 ;%0Aim
@@ -227,16 +227,41 @@
 Assert;%0A
+import org.junit.Before;%0A
 import o
@@ -345,16 +345,58 @@
 t4;%0A%0A/**
+ Tests for creating valid Location objects
  */%0A@Run
@@ -475,81 +475,393 @@
  = n
-ew Location(%22Los Angeles%22);%0A  Location blankLocation = new Location(%22 %22);
+ull;%0A  Location invalidLocation = null;%0A%0A  @Before%0A  public void init() %7B%0A    try %7B%0A      location = LocationUtils.getLocationObject(%22Los Angeles%22);%0A    %7D catch (IllegalStateException%0A        %7C IOException%0A        %7C ApiException%0A        %7C InterruptedException%0A        %7C ArrayIndexOutOfBoundsException e) %7B%0A      System.out.println(%22Error in creating valid location object.%22);%0A    %7D%0A  %7D
 %0A%0A  
@@ -2323,1273 +2323,471 @@
 %0A%0A  
-@Test%0A  public void checkBlankAddressField() %7B%0A    String actual = blankLocation.getAddress();%0A    String expected = %22 %22;%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A  @Test%0A  public void checkBlankFormattedAddressField() %7B%0A    String actual = blankLocation.getAddressFormatted();%0A    String expected = null;%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A  @Test%0A  public void checkBlankLatitude() %7B%0A    Double actual = blankLocation.getLat();%0A    Double expected = 0.0;%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A  @Test%0A  public void checkBlankLongitude() %7B%0A    Double actual = blankLocation.getLng();%0A    Double expected = 0.0;%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A  @Test%0A  public void checkBlankCoords() %7B%0A    LatLng actual = blankLocation.getCoords();%0A    LatLng expected = null;%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A  @Test%0A  public void checkBlankTimeZoneID() %7B%0A    String actual = blankLocation.getTimeZoneID();%0A    String expected = null;%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A  @Test%0A  public void checkBlankTimeZoneName() %7B%0A    String actual = blankLocation.getTimeZoneName();%0A    String expected = null;%0A    Assert.assertEquals(expected, actual);%0A  %7D%0A%0A  @Test%0A  public void checkBlankTimeZone() %7B%0A    TimeZone
+/** Invalid location input should not create a location object */%0A  @Test%0A  public void checkInvalidLocation() %7B%0A    try %7B%0A      invalidLocation = LocationUtils.getLocationObject(%22gibberish location input%22);%0A    %7D catch (IllegalStateException%0A        %7C IOException%0A        %7C ApiException%0A        %7C InterruptedException%0A        %7C ArrayIndexOutOfBoundsException e) %7B%0A      System.out.println(%22Correct error in creating invalid location object.%22);%0A    %7D%0A    Location
  act
@@ -2796,21 +2796,23 @@
 l = 
-blank
+invalid
 Location
 .get
@@ -2811,36 +2811,22 @@
 tion
-.getTimeZone();%0A    TimeZ
+;%0A    Locati
 on
-e
  exp

Update testing so blank location returns null