This commit is contained in:
Looly
2024-09-24 00:35:58 +08:00
parent 4afb8c581e
commit 1b92f58bae
32 changed files with 554 additions and 374 deletions

View File

@@ -70,14 +70,14 @@ public class BeanPathGetOrSetValueTest {
@Test
public void getValueTest() {
final BeanPath pattern = new BeanPath("$.userInfo.examInfoDict[0].id");
final BeanPath<Object> pattern = BeanPath.of("$.userInfo.examInfoDict[0].id");
final Object result = pattern.getValue(tempMap);
Assertions.assertEquals(1, result);
}
@Test
public void setValueTest() {
final BeanPath pattern = new BeanPath("userInfo.examInfoDict[0].id");
final BeanPath<Object> pattern = BeanPath.of("userInfo.examInfoDict[0].id");
pattern.setValue(tempMap, 2);
final Object result = pattern.getValue(tempMap);
Assertions.assertEquals(2, result);
@@ -85,7 +85,7 @@ public class BeanPathGetOrSetValueTest {
@Test
public void getMapTest () {
final BeanPath pattern = new BeanPath("userInfo[id, photoPath]");
final BeanPath<Object> pattern = BeanPath.of("userInfo[id, photoPath]");
@SuppressWarnings("unchecked")
final Map<String, Object> result = (Map<String, Object>)pattern.getValue(tempMap);
Assertions.assertEquals(1, result.get("id"));
@@ -98,7 +98,7 @@ public class BeanPathGetOrSetValueTest {
dataMap.put("aa", "value0");
dataMap.put("aa.bb.cc", "value111111");// key 是类名 格式 带 ' . '
final BeanPath pattern = new BeanPath("'aa.bb.cc'");
final BeanPath<Object> pattern = BeanPath.of("'aa.bb.cc'");
Assertions.assertEquals("value111111", pattern.getValue(dataMap));
}
@@ -106,7 +106,7 @@ public class BeanPathGetOrSetValueTest {
public void issue2362Test() {
final Map<String, Object> map = new HashMap<>();
BeanPath beanPath = BeanPath.of("list[0].name");
BeanPath<Object> beanPath = BeanPath.of("list[0].name");
beanPath.setValue(map, "张三");
Assertions.assertEquals("{list=[{name=张三}]}", map.toString());
@@ -125,7 +125,7 @@ public class BeanPathGetOrSetValueTest {
public void putTest() {
final Map<String, Object> map = new HashMap<>();
final BeanPath beanPath = BeanPath.of("list[1].name");
final BeanPath<Object> beanPath = BeanPath.of("list[1].name");
beanPath.setValue(map, "张三");
Assertions.assertEquals("{list=[null, {name=张三}]}", map.toString());
}

View File

@@ -23,7 +23,7 @@ public class BeanPathTest {
@Test
void parseDotTest() {
BeanPath beanPath = new BeanPath("userInfo.examInfoDict[0].id");
BeanPath<Object> beanPath = BeanPath.of("userInfo.examInfoDict[0].id");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("examInfoDict[0].id", beanPath.getChild());
@@ -42,7 +42,7 @@ public class BeanPathTest {
@Test
void parseDotWithQuoteTest() {
BeanPath beanPath = new BeanPath("'userInfo'.examInfoDict[0].'id'");
BeanPath<Object> beanPath = BeanPath.of("'userInfo'.examInfoDict[0].'id'");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("examInfoDict[0].'id'", beanPath.getChild());
@@ -61,7 +61,7 @@ public class BeanPathTest {
@Test
void parseDotWithQuoteTest2() {
BeanPath beanPath = new BeanPath("userInfo.'examInfoDict'[0].id");
BeanPath<Object> beanPath = BeanPath.of("userInfo.'examInfoDict'[0].id");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("'examInfoDict'[0].id", beanPath.getChild());
@@ -80,7 +80,7 @@ public class BeanPathTest {
@Test
void parseBucketTest() {
BeanPath beanPath = new BeanPath("[userInfo][examInfoDict][0][id]");
BeanPath<Object> beanPath = BeanPath.of("[userInfo][examInfoDict][0][id]");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("[examInfoDict][0][id]", beanPath.getChild());
@@ -99,7 +99,7 @@ public class BeanPathTest {
@Test
void parseBucketWithQuoteTest() {
BeanPath beanPath = new BeanPath("['userInfo']['examInfoDict'][0][id]");
BeanPath<Object> beanPath = BeanPath.of("['userInfo']['examInfoDict'][0][id]");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("['examInfoDict'][0][id]", beanPath.getChild());
@@ -118,7 +118,7 @@ public class BeanPathTest {
@Test
void parseBucketWithQuoteTest2() {
BeanPath beanPath = new BeanPath("[userInfo][examInfoDict][0]['id']");
BeanPath<Object> beanPath = BeanPath.of("[userInfo][examInfoDict][0]['id']");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("[examInfoDict][0]['id']", beanPath.getChild());
@@ -137,7 +137,7 @@ public class BeanPathTest {
@Test
void rangePathTest() {
BeanPath beanPath = new BeanPath("[userInfo][2:3]");
BeanPath<Object> beanPath = BeanPath.of("[userInfo][2:3]");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("[2:3]", beanPath.getChild());
@@ -148,7 +148,7 @@ public class BeanPathTest {
@Test
void listPathTest() {
BeanPath beanPath = new BeanPath("[userInfo][1,2,3]");
BeanPath<Object> beanPath = BeanPath.of("[userInfo][1,2,3]");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("[1,2,3]", beanPath.getChild());
@@ -159,7 +159,7 @@ public class BeanPathTest {
@Test
void listKeysPathTest() {
BeanPath beanPath = new BeanPath("[userInfo]['a', 'b', 'c']");
BeanPath<Object> beanPath = BeanPath.of("[userInfo]['a', 'b', 'c']");
Assertions.assertEquals("userInfo", beanPath.getNode().toString());
Assertions.assertEquals("['a', 'b', 'c']", beanPath.getChild());

View File

@@ -329,7 +329,7 @@ public class ConvertTest {
@Test
public void toClassTest(){
final Class<?> convert = ConvertUtil.convert(Class.class, "org.dromara.hutool.core.support.ConvertTest.Product");
final Class<?> convert = ConvertUtil.convert(Class.class, "org.dromara.hutool.core.convert.ConvertTest.Product");
Assertions.assertSame(Product.class, convert);
}

View File

@@ -16,12 +16,14 @@
package org.dromara.hutool.core.lang;
import lombok.Data;
import org.dromara.hutool.core.exception.HutoolException;
import org.dromara.hutool.core.thread.ThreadUtil;
import lombok.Data;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import java.time.Duration;
import java.util.concurrent.LinkedBlockingQueue;
@@ -30,8 +32,13 @@ import java.util.concurrent.TimeUnit;
public class SingletonTest {
/**
* JDK8下使用了SafeConcurrentHashMap为了解决JDK-8161372问题<br>
* 但是会导致可能的对象多次创建此处屏蔽JDK8的测试
*/
@SuppressWarnings("resource")
@Test
@DisabledOnJre(JRE.JAVA_8)
public void getTest(){
// 此测试中使用1000个线程获取单例对象其间对象只被创建一次
ThreadUtil.concurrencyTest(1000, ()-> Singleton.get(TestBean.class));

View File

@@ -17,7 +17,6 @@
package org.dromara.hutool.core.util;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.util.JdkUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;