ParseQS and Global made into packages
This commit is contained in:
51
src/test/java/com/github/nkzawa/parseqs/ParseQSTest.java
Normal file
51
src/test/java/com/github/nkzawa/parseqs/ParseQSTest.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.github.nkzawa.parseqs;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ParseQSTest {
|
||||
|
||||
@Test
|
||||
public void decode() {
|
||||
Map<String, String> queryObject = ParseQS.decode("foo=bar");
|
||||
assertThat(queryObject.get("foo"), is("bar"));
|
||||
|
||||
queryObject = ParseQS.decode("france=paris&germany=berlin");
|
||||
assertThat(queryObject.get("france"), is("paris"));
|
||||
assertThat(queryObject.get("germany"), is("berlin"));
|
||||
|
||||
queryObject = ParseQS.decode("india=new%20delhi");
|
||||
assertThat(queryObject.get("india"), is("new delhi"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encode() {
|
||||
Map<String, String> obj;
|
||||
|
||||
obj = new HashMap<String, String>() {{
|
||||
put("a", "b");
|
||||
}};
|
||||
assertThat(ParseQS.encode(obj), is("a=b"));
|
||||
|
||||
obj = new LinkedHashMap<String, String>() {{
|
||||
put("a", "b");
|
||||
put("c", "d");
|
||||
}};
|
||||
assertThat(ParseQS.encode(obj), is("a=b&c=d"));
|
||||
|
||||
obj = new LinkedHashMap<String, String>() {{
|
||||
put("a", "b");
|
||||
put("c", "tobi rocks");
|
||||
}};
|
||||
assertThat(ParseQS.encode(obj), is("a=b&c=tobi%20rocks"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user