From c09cd02723a695e5a239f1b3b382609ff4360da0 Mon Sep 17 00:00:00 2001 From: calvin1978 Date: Tue, 24 Jan 2017 13:03:56 +0800 Subject: [PATCH] fix UT --- .../modules/utils/io/URLResourceUtil.java | 2 ++ .../modules/utils/io/URLResourceTest.java | 14 ++------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/modules/utils/src/main/java/org/springside/modules/utils/io/URLResourceUtil.java b/modules/utils/src/main/java/org/springside/modules/utils/io/URLResourceUtil.java index 94878833a..d25749eff 100644 --- a/modules/utils/src/main/java/org/springside/modules/utils/io/URLResourceUtil.java +++ b/modules/utils/src/main/java/org/springside/modules/utils/io/URLResourceUtil.java @@ -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)) { diff --git a/modules/utils/src/test/java/org/springside/modules/utils/io/URLResourceTest.java b/modules/utils/src/test/java/org/springside/modules/utils/io/URLResourceTest.java index 3491d1299..bc9a8a51c 100644 --- a/modules/utils/src/test/java/org/springside/modules/utils/io/URLResourceTest.java +++ b/modules/utils/src/test/java/org/springside/modules/utils/io/URLResourceTest.java @@ -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);