package com.xamoom.android.xamoomsdk.xamoomsdk.Utils;

import com.xamoom.android.xamoomsdk.Enums.ContentFlags;
import com.xamoom.android.xamoomsdk.Enums.ContentSortFlags;
import com.xamoom.android.xamoomsdk.Enums.SpotFlags;
import com.xamoom.android.xamoomsdk.Enums.SpotSortFlags;
import com.xamoom.android.xamoomsdk.Utils.UrlUtil;

import org.junit.Test;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import static junit.framework.Assert.assertEquals;

public class UrlUtilTests {
  @Test
  public void testAddContentParameter() throws Exception {
    Map<String, String> checkParams = new HashMap<>();
    checkParams.put("lang", "en");
    checkParams.put("preview", "true");
    checkParams.put("public-only", "true");

    Map<String, String> params = UrlUtil.addContentParameter(UrlUtil.getUrlParameter("en"),
        EnumSet.of(ContentFlags.PREVIEW, ContentFlags.PRIVATE));

    assertEquals(params, checkParams);
  }

  @Test
  public void testAddContentSortingParameter() throws Exception {
    Map<String, String> checkParams = new HashMap<>();
    checkParams.put("lang", "en");
    checkParams.put("sort", "name,-name");

    Map<String, String> params = UrlUtil.addContentSortingParameter(UrlUtil.getUrlParameter("en"),
        EnumSet.of(ContentSortFlags.NAME, ContentSortFlags.NAME_DESC));

    assertEquals(params, checkParams);
  }

  @Test
  public void testAddSpotParameter() throws Exception {
    Map<String, String> checkParams = new HashMap<>();
    checkParams.put("lang", "en");
    checkParams.put("include_content", "true");
    checkParams.put("include_markers", "true");

    Map<String, String> params = UrlUtil.addSpotParameter(UrlUtil.getUrlParameter("en"),
        EnumSet.of(SpotFlags.INCLUDE_CONTENT, SpotFlags.INCLUDE_MARKERS, SpotFlags.HAS_LOCATION));

    assertEquals(params, checkParams);
  }

  @Test
  public void testAddSpotSortingParameter() throws Exception {
    Map<String, String> checkParams = new HashMap<>();
    checkParams.put("lang", "en");
    checkParams.put("sort", "name,-name,distance,-distance");

    Map<String, String> params = UrlUtil.addSpotSortingParameter(UrlUtil.getUrlParameter("en"),
        EnumSet.of(SpotSortFlags.NAME, SpotSortFlags.NAME_DESC, SpotSortFlags.DISTANCE, SpotSortFlags.DISTANCE_DESC));

    assertEquals(params, checkParams);
  }

  @Test
  public void testAddPagingToUrl() throws Exception {
    Map<String, String> checkParams = new HashMap<>();
    checkParams.put("lang", "en");
    checkParams.put("page[size]", "10");
    checkParams.put("page[cursor]", "1");

    Map<String, String> params = UrlUtil.addPagingToUrl(UrlUtil.getUrlParameter("en"), 10, "1");

    assertEquals(params, checkParams);
  }

}

@@ -480,36 +480,473 @@
 ls;%0A
-%0Apublic class UrlUtilTests %7B
+import static junit.framework.TestCase.assertNotNull;%0A%0Apublic class UrlUtilTests %7B%0A%0A  @Test%0A  public void testConstructor() %7B%0A    assertNotNull(new UrlUtil());%0A  %7D%0A%0A  @Test%0A  public void testAddContentParameterWithNull() %7B%0A    Map%3CString, String%3E checkParams = new HashMap%3C%3E();%0A    checkParams.put(%22lang%22, %22en%22);%0A%0A    Map%3CString, String%3E params = UrlUtil.addContentParameter(UrlUtil.getUrlParameter(%22en%22),%0A        null);%0A%0A    assertEquals(params, checkParams);%0A  %7D%0A
 %0A  @
@@ -1802,32 +1802,364 @@
 ckParams);%0A  %7D%0A%0A
+  @Test%0A  public void testAddContentSortingParameterWithNull() throws Exception %7B%0A    Map%3CString, String%3E checkParams = new HashMap%3C%3E();%0A    checkParams.put(%22lang%22, %22en%22);%0A%0A    Map%3CString, String%3E params = UrlUtil.addContentSortingParameter(UrlUtil.getUrlParameter(%22en%22),%0A        null);%0A%0A    assertEquals(params, checkParams);%0A  %7D%0A%0A
   @Test%0A  public
@@ -2618,32 +2618,344 @@
 ckParams);%0A  %7D%0A%0A
+  @Test%0A  public void testAddSpotParameterWithNull() throws Exception %7B%0A    Map%3CString, String%3E checkParams = new HashMap%3C%3E();%0A    checkParams.put(%22lang%22, %22en%22);%0A%0A    Map%3CString, String%3E params = UrlUtil.addSpotParameter(UrlUtil.getUrlParameter(%22en%22),%0A        null);%0A%0A    assertEquals(params, checkParams);%0A  %7D%0A%0A
   @Test%0A  public
@@ -3414,32 +3414,358 @@
 ckParams);%0A  %7D%0A%0A
+  @Test%0A  public void testAddSpotSortingParameterWithNull() throws Exception %7B%0A    Map%3CString, String%3E checkParams = new HashMap%3C%3E();%0A    checkParams.put(%22lang%22, %22en%22);%0A%0A    Map%3CString, String%3E params = UrlUtil.addSpotSortingParameter(UrlUtil.getUrlParameter(%22en%22),%0A        null);%0A%0A    assertEquals(params, checkParams);%0A  %7D%0A%0A
   @Test%0A  public

Add unittests