mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-02 20:02:37 +08:00
🎨 增加一些单元测试代码
This commit is contained in:
parent
6b21f1a234
commit
c1e7d095ed
@ -11,6 +11,9 @@ import java.util.Base64;
|
||||
|
||||
import static org.apache.commons.io.FileUtils.openOutputStream;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class FileUtils {
|
||||
|
||||
/**
|
||||
@ -21,7 +24,8 @@ public class FileUtils {
|
||||
* @param ext 扩展名
|
||||
* @param tmpDirFile 临时文件夹目录
|
||||
*/
|
||||
public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException {
|
||||
public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile)
|
||||
throws IOException {
|
||||
File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile);
|
||||
|
||||
resultFile.deleteOnExit();
|
||||
|
@ -0,0 +1,34 @@
|
||||
package me.chanjar.weixin.common.util.fs;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class FileUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testCreateTmpFile() throws IOException {
|
||||
String strings = "abc";
|
||||
File tmpFile = FileUtils.createTmpFile(new ByteArrayInputStream(strings.getBytes()), "name", "txt");
|
||||
System.out.println(tmpFile);
|
||||
List<String> lines = IOUtils.readLines(Files.newInputStream(tmpFile.toPath()), Charset.defaultCharset());
|
||||
assertThat(lines).hasSize(1);
|
||||
assertThat(lines.get(0)).isEqualTo(strings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTestCreateTmpFile() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImageToBase64ByStream() {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user