Browse Source

单元测试

master
richie 5 years ago
parent
commit
b394dad562
  1. 6
      src/main/java/com/fanruan/api/util/IOKit.java
  2. 7
      src/test/java/com/fanruan/api/util/IOKitTest.java
  3. 1
      src/test/resources/com/fanruan/api/util/iokit.txt

6
src/main/java/com/fanruan/api/util/IOKit.java

@ -13,7 +13,7 @@ import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.nio.channels.Channel;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
/**
* @author richie
@ -108,7 +108,7 @@ public class IOKit {
* @return 读取出来的字符串
* @throws UnsupportedEncodingException 编码类型不支持则抛出此异常
*/
public static String inputStream2String(InputStream is, StandardCharsets charset)
public static String inputStream2String(InputStream is, Charset charset)
throws UnsupportedEncodingException {
return CommonIOUtils.inputStream2String(is, charset.toString());
}
@ -196,7 +196,7 @@ public class IOKit {
* @param encode 读取资源所用的编码
* @return 表示资源内容的字符串
*/
public static String readResourceAsString(String path, StandardCharsets encode) {
public static String readResourceAsString(String path, Charset encode) {
return IOUtils.readResourceAsString(path, encode.toString());
}

7
src/test/java/com/fanruan/api/util/IOKitTest.java

@ -3,6 +3,7 @@ package com.fanruan.api.util;
import com.fanruan.api.Prepare;
import org.junit.Assert;
import org.junit.Test;
import sun.nio.cs.ext.GBK;
import java.nio.charset.StandardCharsets;
@ -17,4 +18,10 @@ public class IOKitTest extends Prepare {
public void testEncode() {
Assert.assertEquals("UTF-8", StandardCharsets.UTF_8.toString());
}
@Test
public void testReadResourceAsString() {
String text = IOKit.readResourceAsString("/com/fanruan/api/util/iokit.txt");
Assert.assertEquals("Hello World!", text);
}
}

1
src/test/resources/com/fanruan/api/util/iokit.txt

@ -0,0 +1 @@
Hello World!
Loading…
Cancel
Save