Skip to content

Commit

Permalink
fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin1978 committed Jan 24, 2017
1 parent 8079272 commit c09cd02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class URLResourceUtil {

/**
* 兼容无前缀, classpath://, file:// 的情况获取文件
*
* 如果以classpath:// 定义的文件不存在会抛出IllegalArgumentException异常,以file://定义的则不会
*/
public static File asFile(String generalPath) throws IOException {
if (StringUtils.startsWith(generalPath, CLASSPATH_PREFIX)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,11 @@ public void file() throws IOException {
File file2 = URLResourceUtil.asFile("file://" + file.getAbsolutePath());
assertThat(FileUtil.toString(file2)).isEqualTo("haha");

try {
URLResourceUtil.asFile("file://" + file.getAbsolutePath() + ".noexist");
fail("should fail");
} catch (Throwable t) {
assertThat(t).isInstanceOf(IllegalArgumentException.class);
}
File file2NotExist = URLResourceUtil.asFile("file://" + file.getAbsolutePath() + ".noexist");

File file3 = URLResourceUtil.asFile(file.getAbsolutePath());
assertThat(FileUtil.toString(file3)).isEqualTo("haha");
try {
URLResourceUtil.asFile(file.getAbsolutePath() + ".noexist");
fail("should fail");
} catch (Throwable t) {
assertThat(t).isInstanceOf(IllegalArgumentException.class);
}
File file3NotExist = URLResourceUtil.asFile(file.getAbsolutePath() + ".noexist");

} finally {
FileUtil.deleteFile(file);
Expand Down

0 comments on commit c09cd02

Please sign in to comment.