/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. 
 */

package org.openlmis.fulfillment.service.request;

import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;

import com.google.common.collect.Maps;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;

public class RequestParametersTest {

  @Test
  public void shouldConstructFromMap() throws Exception {
    RequestParameters params = RequestParameters.init().set("a", "b");
    assertThat(toMap(params), hasEntry("a", "b"));
  }

  @Test
  public void shouldSetParameter() throws Exception {
    HashMap<String, Object> map = new HashMap<>();
    map.put("a", "b");

    RequestParameters requestParameters = RequestParameters.of(map);
    assertThat(toMap(requestParameters), hasEntry("a", "b"));
  }

  @Test
  public void shouldNotSetParametersValueIsNull() throws Exception {
    RequestParameters params = RequestParameters.init().set("a", null);
    assertThat(toMap(params), not(hasKey("a")));
  }

  @Test
  public void shouldSetAllParametersFromOtherInstance() throws Exception {
    RequestParameters parent = RequestParameters.init().set("a", "b");
    RequestParameters params = RequestParameters.init().setAll(parent);

    assertThat(toMap(params), hasEntry("a", "b"));
  }

  private Map<String, Object> toMap(RequestParameters parameters) {
    Map<String, Object> map = Maps.newHashMap();
    parameters.forEach(e -> map.put(e.getKey(), e.getValue()));

    return map;
  }
}

@@ -1281,32 +1281,107 @@
 ows Exception %7B%0A
+    HashMap%3CString, Object%3E map = new HashMap%3C%3E();%0A    map.put(%22a%22, %22b%22);%0A%0A
     RequestParam
@@ -1378,37 +1378,48 @@
 questParameters 
-param
+requestParameter
 s = RequestParam
@@ -1424,35 +1424,22 @@
 ameters.
-init().set(%22a%22, %22b%22
+of(map
 );%0A    a
@@ -1446,37 +1446,48 @@
 ssertThat(toMap(
-param
+requestParameter
 s), hasEntry(%22a%22
@@ -1566,83 +1566,8 @@
 n %7B%0A
-    HashMap%3CString, Object%3E map = new HashMap%3C%3E();%0A    map.put(%22a%22, %22b%22);%0A%0A
     
@@ -1584,32 +1584,21 @@
 ameters 
-requestParameter
+param
 s = Requ
@@ -1603,38 +1603,51 @@
 questParameters.
-of(map
+init().set(%22a%22, %22b%22
 );%0A    assertTha
@@ -1654,32 +1654,21 @@
 t(toMap(
-requestParameter
+param
 s), hasE

fix test names