This commit is contained in:
Looly
2022-05-12 00:47:19 +08:00
parent eaa80f55a6
commit 9835d1bd80
7 changed files with 47 additions and 31 deletions

View File

@@ -86,14 +86,14 @@ public class BeanPathTest {
@Test
public void getTest() {
final BeanPath pattern = BeanPath.create("userInfo.examInfoDict[0].id");
final BeanPath pattern = BeanPath.of("userInfo.examInfoDict[0].id");
final Object result = pattern.get(tempMap);
Assert.assertEquals(1, result);
}
@Test
public void setTest() {
final BeanPath pattern = BeanPath.create("userInfo.examInfoDict[0].id");
final BeanPath pattern = BeanPath.of("userInfo.examInfoDict[0].id");
pattern.set(tempMap, 2);
final Object result = pattern.get(tempMap);
Assert.assertEquals(2, result);
@@ -101,7 +101,7 @@ public class BeanPathTest {
@Test
public void getMapTest () {
final BeanPath pattern = BeanPath.create("userInfo[id, photoPath]");
final BeanPath pattern = BeanPath.of("userInfo[id, photoPath]");
@SuppressWarnings("unchecked")
final Map<String, Object> result = (Map<String, Object>)pattern.get(tempMap);
Assert.assertEquals(1, result.get("id"));
@@ -114,7 +114,15 @@ public class BeanPathTest {
dataMap.put("aa", "value0");
dataMap.put("aa.bb.cc", "value111111");// key 是类名 格式 带 ' . '
final BeanPath pattern = BeanPath.create("'aa.bb.cc'");
final BeanPath pattern = BeanPath.of("'aa.bb.cc'");
Assert.assertEquals("value111111", pattern.get(dataMap));
}
@Test
public void compileTest(){
final BeanPath of = BeanPath.of("'abc.dd'.ee.ff'.'");
Assert.assertEquals("abc.dd", of.getPatternParts().get(0));
Assert.assertEquals("ee", of.getPatternParts().get(1));
Assert.assertEquals("ff.", of.getPatternParts().get(2));
}
}

View File

@@ -704,7 +704,7 @@ public class BeanUtilTest {
testPojo.setTestPojo2List(new TestPojo2[]{testPojo2, testPojo3});
final BeanPath beanPath = BeanPath.create("testPojo2List.age");
final BeanPath beanPath = BeanPath.of("testPojo2List.age");
final Object o = beanPath.get(testPojo);
Assert.assertEquals(Integer.valueOf(2), ArrayUtil.get(o, 0));