mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix test
This commit is contained in:
parent
0760e44c12
commit
13aff5c734
@ -23,6 +23,7 @@ import org.dromara.hutool.core.io.resource.ResourceUtil;
|
|||||||
import org.dromara.hutool.core.io.stream.BOMInputStream;
|
import org.dromara.hutool.core.io.stream.BOMInputStream;
|
||||||
import org.dromara.hutool.core.io.unit.DataSizeUtil;
|
import org.dromara.hutool.core.io.unit.DataSizeUtil;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
|
import org.dromara.hutool.core.lang.Console;
|
||||||
import org.dromara.hutool.core.net.url.URLUtil;
|
import org.dromara.hutool.core.net.url.URLUtil;
|
||||||
import org.dromara.hutool.core.reflect.ClassUtil;
|
import org.dromara.hutool.core.reflect.ClassUtil;
|
||||||
import org.dromara.hutool.core.regex.ReUtil;
|
import org.dromara.hutool.core.regex.ReUtil;
|
||||||
@ -2558,6 +2559,7 @@ public class FileUtil extends PathUtil {
|
|||||||
*/
|
*/
|
||||||
public static File getWebRoot() {
|
public static File getWebRoot() {
|
||||||
final String classPath = ClassUtil.getClassPath();
|
final String classPath = ClassUtil.getClassPath();
|
||||||
|
Console.log(classPath);
|
||||||
if (StrUtil.isNotBlank(classPath)) {
|
if (StrUtil.isNotBlank(classPath)) {
|
||||||
return getParent(file(classPath), 2);
|
return getParent(file(classPath), 2);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import org.dromara.hutool.core.io.resource.ClassPathResource;
|
|||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||||
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -22,14 +24,26 @@ public class ClassPathResourceTest {
|
|||||||
Assertions.assertTrue(StrUtil.isNotEmpty(content));
|
Assertions.assertTrue(StrUtil.isNotEmpty(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test()
|
||||||
|
@EnabledForJreRange(max = JRE.JAVA_8)
|
||||||
public void readStringTest2() {
|
public void readStringTest2() {
|
||||||
|
// JDK9+中因为模块的加入,根路径读取可能为空
|
||||||
// 读取classpath根目录测试
|
// 读取classpath根目录测试
|
||||||
final ClassPathResource resource = new ClassPathResource("/");
|
final ClassPathResource resource = new ClassPathResource("/");
|
||||||
final String content = resource.readUtf8Str();
|
final String content = resource.readUtf8Str();
|
||||||
Assertions.assertTrue(StrUtil.isNotEmpty(content));
|
Assertions.assertTrue(StrUtil.isNotEmpty(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test()
|
||||||
|
@EnabledForJreRange(min = JRE.JAVA_9)
|
||||||
|
public void readStringTestForJdk9() {
|
||||||
|
// JDK9+中因为模块的加入,根路径读取可能为空
|
||||||
|
// 读取classpath根目录测试
|
||||||
|
final ClassPathResource resource = new ClassPathResource("/");
|
||||||
|
final String content = resource.readUtf8Str();
|
||||||
|
Assertions.assertTrue(StrUtil.isEmpty(content));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readTest() throws IOException {
|
public void readTest() throws IOException {
|
||||||
final ClassPathResource resource = new ClassPathResource("test.properties");
|
final ClassPathResource resource = new ClassPathResource("test.properties");
|
||||||
|
@ -19,6 +19,8 @@ import org.dromara.hutool.core.util.SystemUtil;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||||
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -250,7 +252,9 @@ public class FileUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnabledForJreRange(max = JRE.JAVA_8)
|
||||||
public void listFileNamesTest() {
|
public void listFileNamesTest() {
|
||||||
|
// JDK9+中,由于模块化问题,获取的classoath路径非项目下,而是junit下的。
|
||||||
List<String> names = FileUtil.listFileNames("classpath:");
|
List<String> names = FileUtil.listFileNames("classpath:");
|
||||||
Assertions.assertTrue(names.contains("hutool.jpg"));
|
Assertions.assertTrue(names.contains("hutool.jpg"));
|
||||||
|
|
||||||
@ -400,7 +404,9 @@ public class FileUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnabledForJreRange(max = JRE.JAVA_8)
|
||||||
public void getWebRootTest() {
|
public void getWebRootTest() {
|
||||||
|
// JDK9+环境中,由于模块问题,junit获取的classpath路径和实际不同
|
||||||
final File webRoot = FileUtil.getWebRoot();
|
final File webRoot = FileUtil.getWebRoot();
|
||||||
Assertions.assertNotNull(webRoot);
|
Assertions.assertNotNull(webRoot);
|
||||||
Assertions.assertEquals("hutool-core", webRoot.getName());
|
Assertions.assertEquals("hutool-core", webRoot.getName());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user