removed URLUtils
This commit is contained in:
1 parent
b380b3af3d
commit
83b62f6079
16 files changed
+104
-303
No files matched your search
@@ -1,13 +1,8 @@
|
||||
package org.scribe.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.scribe.utils.URLUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
@@ -81,8 +76,8 @@ public class ParameterListTest
|
||||
params.add("param1", "v1");
|
||||
params.add("param6", "v2");
|
||||
params.add("a_param", "v3");
|
||||
params.add("param2", "v4");
|
||||
Assert.assertEquals("a_param=v3¶m1=v1¶m2=v4¶m6=v2", params.sort().asFormUrlEncodedString());
|
||||
params.add("param1", "v4");
|
||||
Assert.assertEquals("a_param=v3¶m1=v1¶m1=v4¶m6=v2", params.sort().asFormUrlEncodedString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.scribe.utils;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author: Pablo Fernandez
|
||||
*/
|
||||
public class OAuthEncoderTest
|
||||
{
|
||||
@Test
|
||||
public void shouldPercentEncodeString()
|
||||
{
|
||||
String plain = "this is a test &^";
|
||||
String encoded = "this%20is%20a%20test%20%26%5E";
|
||||
assertEquals(encoded, OAuthEncoder.encode(plain));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormURLDecodeString()
|
||||
{
|
||||
String encoded = "this+is+a+test+%26%5E";
|
||||
String plain = "this is a test &^";
|
||||
assertEquals(plain, OAuthEncoder.decode(encoded));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPercentEncodeAllSpecialCharacters()
|
||||
{
|
||||
String plain = "!*'();:@&=+$,/?#[]";
|
||||
String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D";
|
||||
assertEquals(encoded, OAuthEncoder.encode(plain));
|
||||
assertEquals(plain, OAuthEncoder.decode(encoded));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotPercentEncodeReservedCharacters()
|
||||
{
|
||||
String plain = "abcde123456-._~";
|
||||
String encoded = plain;
|
||||
assertEquals(encoded, OAuthEncoder.encode(plain));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfStringToEncodeIsNull()
|
||||
{
|
||||
String toEncode = null;
|
||||
OAuthEncoder.encode(toEncode);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfStringToDecodeIsNull()
|
||||
{
|
||||
String toDecode = null;
|
||||
OAuthEncoder.decode(toDecode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPercentEncodeCorrectlyTwitterCodingExamples()
|
||||
{
|
||||
// These tests are part of the Twitter dev examples here -> https://dev.twitter.com/docs/auth/percent-encoding-parameters
|
||||
String sources[] = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"};
|
||||
String encoded[] = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"};
|
||||
|
||||
for(int i = 0; i < sources.length; i++)
|
||||
{
|
||||
Assert.assertEquals(encoded[i], OAuthEncoder.encode(sources[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
package org.scribe.utils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
public class URLUtilsTest
|
||||
{
|
||||
@Test
|
||||
public void shouldPercentEncodeMap()
|
||||
{
|
||||
Map<String, String> params = new LinkedHashMap<String, String>();
|
||||
params.put("key", "value");
|
||||
params.put("key with spaces", "value with spaces");
|
||||
params.put("&symbols!", "#!");
|
||||
|
||||
String expected = "key=value&key+with+spaces=value+with+spaces&%26symbols%21=%23%21";
|
||||
assertEquals(expected, URLUtils.formURLEncodeMap(params));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnEmptyStringForEmptyMap()
|
||||
{
|
||||
Map<String, String> params = new LinkedHashMap<String, String>();
|
||||
String expected = "";
|
||||
assertEquals(expected, URLUtils.formURLEncodeMap(params));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormURLEncodeMapWithMissingValues()
|
||||
{
|
||||
Map<String, String> params = new LinkedHashMap<String, String>();
|
||||
params.put("key", "value");
|
||||
params.put("key with spaces", null);
|
||||
|
||||
String expected = "key=value&key+with+spaces";
|
||||
assertEquals(expected, URLUtils.formURLEncodeMap(params));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPercentEncodeString()
|
||||
{
|
||||
String toEncode = "this is a test &^";
|
||||
String expected = "this%20is%20a%20test%20%26%5E";
|
||||
assertEquals(expected, URLUtils.percentEncode(toEncode));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormURLEncodeString()
|
||||
{
|
||||
String toEncode = "this is a test &^";
|
||||
String expected = "this+is+a+test+%26%5E";
|
||||
assertEquals(expected, URLUtils.formURLEncode(toEncode));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormURLDecodeString()
|
||||
{
|
||||
String toDecode = "this+is+a+test+%26%5E";
|
||||
String expected = "this is a test &^";
|
||||
assertEquals(expected, URLUtils.formURLDecode(toDecode));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPercentEncodeAllSpecialCharacters()
|
||||
{
|
||||
String plain = "!*'();:@&=+$,/?#[]";
|
||||
String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D";
|
||||
assertEquals(encoded, URLUtils.percentEncode(plain));
|
||||
assertEquals(plain, URLUtils.formURLDecode(encoded));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotPercentEncodeReservedCharacters()
|
||||
{
|
||||
String plain = "abcde123456-._~";
|
||||
String encoded = plain;
|
||||
assertEquals(encoded, URLUtils.percentEncode(plain));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfMapIsNull()
|
||||
{
|
||||
Map<String, String> nullMap = null;
|
||||
URLUtils.formURLEncodeMap(nullMap);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfStringToEncodeIsNull()
|
||||
{
|
||||
String toEncode = null;
|
||||
URLUtils.percentEncode(toEncode);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfStringToDecodeIsNull()
|
||||
{
|
||||
String toDecode = null;
|
||||
URLUtils.formURLDecode(toDecode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPercentEncodePlusSymbol()
|
||||
{
|
||||
String plain = "7aEP+jNAwvjc0mjhqg0nuXPf";
|
||||
String encoded = "7aEP%2BjNAwvjc0mjhqg0nuXPf";
|
||||
|
||||
Assert.assertEquals(encoded, URLUtils.percentEncode(plain));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldURLDecodePlusSymbol()
|
||||
{
|
||||
String encoded = "oauth_verifier=7aEP%2BjNAwvjc0mjhqg0nuXPf";
|
||||
String expected = "oauth_verifier=7aEP+jNAwvjc0mjhqg0nuXPf";
|
||||
|
||||
Assert.assertEquals(expected, URLUtils.formURLDecode(encoded));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPercentEncodeCorrectlyTwitterCodingExamples()
|
||||
{
|
||||
// These tests are part of the Twitter dev examples here -> https://dev.twitter.com/docs/auth/percent-encoding-parameters
|
||||
String sources[] = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"};
|
||||
String encoded[] = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"};
|
||||
|
||||
for(int i = 0; i < sources.length; i++)
|
||||
{
|
||||
Assert.assertEquals(encoded[i], URLUtils.percentEncode(sources[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user