Add unit tests

This commit is contained in:
xhh 2015-05-25 12:32:24 +08:00
parent 85d0e08a80
commit 19a8ac4841
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,42 @@
package io.swagger.client;
import static org.junit.Assert.*;
import org.junit.*;
public class ApiInvokerTest {
@Test
public void testSelectHeaderAccept() {
String[] accepts = { "APPLICATION/JSON", "APPLICATION/XML" };
assertEquals("application/json", ApiInvoker.selectHeaderAccept(accepts));
accepts = new String[] { "application/json", "application/xml" };
assertEquals("application/json", ApiInvoker.selectHeaderAccept(accepts));
accepts = new String[] { "application/xml", "application/json" };
assertEquals("application/json", ApiInvoker.selectHeaderAccept(accepts));
accepts = new String[] { "text/plain", "application/xml" };
assertEquals("text/plain,application/xml", ApiInvoker.selectHeaderAccept(accepts));
accepts = new String[] { };
assertEquals("application/json", ApiInvoker.selectHeaderAccept(accepts));
}
@Test
public void testSelectHeaderContentType() {
String[] contentTypes = { "APPLICATION/JSON", "APPLICATION/XML" };
assertEquals("application/json", ApiInvoker.selectHeaderContentType(contentTypes));
contentTypes = new String[] { "application/json", "application/xml" };
assertEquals("application/json", ApiInvoker.selectHeaderContentType(contentTypes));
contentTypes = new String[] { "application/xml", "application/json" };
assertEquals("application/json", ApiInvoker.selectHeaderContentType(contentTypes));
contentTypes = new String[] { "text/plain", "application/xml" };
assertEquals("text/plain", ApiInvoker.selectHeaderContentType(contentTypes));
contentTypes = new String[] { };
assertEquals("application/json", ApiInvoker.selectHeaderContentType(contentTypes));
}
}

View File

@ -0,0 +1,32 @@
package io.swagger.client;
import static org.junit.Assert.*;
import org.junit.*;
public class StringUtilTest {
@Test
public void testContainsIgnoreCase() {
assertTrue(StringUtil.containsIgnoreCase(new String[]{ "abc" }, "abc"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{ "abc" }, "ABC"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{ "ABC" }, "abc"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{ null, "abc" }, "ABC"));
assertTrue(StringUtil.containsIgnoreCase(new String[]{ null, "abc" }, null));
assertFalse(StringUtil.containsIgnoreCase(new String[]{ "abc" }, "def"));
assertFalse(StringUtil.containsIgnoreCase(new String[]{ }, "ABC"));
assertFalse(StringUtil.containsIgnoreCase(new String[]{ }, null));
}
@Test
public void testJoin() {
String[] array = { "aa", "bb", "cc" };
assertEquals("aa,bb,cc", StringUtil.join(array, ","));
assertEquals("aa, bb, cc", StringUtil.join(array, ", "));
assertEquals("aabbcc", StringUtil.join(array, ""));
assertEquals("aa bb cc", StringUtil.join(array, " "));
assertEquals("aa\nbb\ncc", StringUtil.join(array, "\n"));
assertEquals("", StringUtil.join(new String[]{ }, ","));
assertEquals("abc", StringUtil.join(new String[]{ "abc" }, ","));
}
}