Initial commit
This commit is contained in:
commit
bfbe536886
59 files changed
+2540
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package org.scribe.utils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
public class MapUtilsTest
|
||||
{
|
||||
|
||||
private Map<String, String> unsorted;
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
unsorted = new LinkedHashMap<String, String>();
|
||||
unsorted.put("d", "fourth");
|
||||
unsorted.put("a", "first");
|
||||
unsorted.put("c", "third");
|
||||
unsorted.put("b", "second");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSortMap()
|
||||
{
|
||||
Map<String, String> sorted = MapUtils.sort(unsorted);
|
||||
List<String> values = new ArrayList<String>(sorted.values());
|
||||
assertEquals("first", values.get(0));
|
||||
assertEquals("second", values.get(1));
|
||||
assertEquals("third", values.get(2));
|
||||
assertEquals("fourth", values.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotModifyTheOriginalMap()
|
||||
{
|
||||
Map<String, String> sorted = MapUtils.sort(unsorted);
|
||||
assertNotSame(sorted, unsorted);
|
||||
|
||||
List<String> values = new ArrayList<String>(unsorted.values());
|
||||
assertEquals("fourth", values.get(0));
|
||||
assertEquals("first", values.get(1));
|
||||
assertEquals("third", values.get(2));
|
||||
assertEquals("second", values.get(3));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionForNullMap()
|
||||
{
|
||||
MapUtils.sort(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.scribe.utils;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
public class PreconditionsTest
|
||||
{
|
||||
|
||||
private static final String ERROR_MSG = "";
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionForNullObjects()
|
||||
{
|
||||
Preconditions.checkNotNull(null, ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionForNullStrings()
|
||||
{
|
||||
Preconditions.checkEmptyString(null, ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionForEmptyStrings()
|
||||
{
|
||||
Preconditions.checkEmptyString("", ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionForSpacesOnlyStrings()
|
||||
{
|
||||
Preconditions.checkEmptyString(" ", ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionForInvalidUrls()
|
||||
{
|
||||
Preconditions.checkValidUrl("this/is/not/a/valid/url", ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionForNullUrls()
|
||||
{
|
||||
Preconditions.checkValidUrl(null, ERROR_MSG);
|
||||
}
|
||||
|
||||
public void shouldAllowValidUrls()
|
||||
{
|
||||
Preconditions.checkValidUrl("http://www.example.com", ERROR_MSG);
|
||||
}
|
||||
|
||||
public void shouldAllowSSLUrls()
|
||||
{
|
||||
Preconditions.checkValidUrl("https://www.example.com", ERROR_MSG);
|
||||
}
|
||||
|
||||
public void shouldAllowOutOfBandAsValidCallbackValue()
|
||||
{
|
||||
Preconditions.checkValidOAuthCallback("oob", ERROR_MSG);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.scribe.utils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class StreamUtilsTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void shouldCorrectlyDecodeAStream()
|
||||
{
|
||||
String value = "expected";
|
||||
InputStream is = new ByteArrayInputStream(value.getBytes());
|
||||
String decoded = StreamUtils.getStreamContents(is);
|
||||
assertEquals("expected", decoded);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldFailForNullParameter()
|
||||
{
|
||||
InputStream is = null;
|
||||
StreamUtils.getStreamContents(is);
|
||||
fail("Must throw exception before getting here");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.scribe.utils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
public class URLUtilsTest
|
||||
{
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@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 shouldPercentEncodeString()
|
||||
{
|
||||
String toEncode = "this is a test &^";
|
||||
String expected = "this+is+a+test+%26%5E";
|
||||
assertEquals(expected, URLUtils.percentEncode(toEncode));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPercentDecodeString()
|
||||
{
|
||||
String toDecode = "this+is+a+test+%26%5E";
|
||||
String expected = "this is a test &^";
|
||||
assertEquals(expected, URLUtils.percentDecode(toDecode));
|
||||
}
|
||||
|
||||
@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.percentDecode(toDecode);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user