mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
|
||||
package org.dromara.hutool.core.text;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.dromara.hutool.core.text.placeholder.StrFormatter;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -62,4 +64,20 @@ public class StrFormatterTest {
|
||||
final String result3 = StrFormatter.formatWith("this is \\\\$$$ for $$$", "$$$", "a", "b");
|
||||
Assertions.assertEquals("this is \\a for b", result3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void formatByBeanTest() {
|
||||
final User user = new User("张三", 18, true);
|
||||
final String s = StrFormatter.formatByBean("User name: {name}, age: {age}, gender: {gender}", user, true);
|
||||
|
||||
Assertions.assertEquals("User name: 张三, age: 18, gender: true", s);
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
private static class User{
|
||||
private String name;
|
||||
private int age;
|
||||
private boolean gender;
|
||||
}
|
||||
}
|
||||
|
@@ -89,10 +89,10 @@ public class StrUtilTest {
|
||||
@Test
|
||||
public void formatTest() {
|
||||
final String template = "你好,我是{name},我的电话是:{phone}";
|
||||
final String result = StrUtil.format(template, Dict.of().set("name", "张三").set("phone", "13888881111"));
|
||||
final String result = StrUtil.formatByMap(template, Dict.of().set("name", "张三").set("phone", "13888881111"));
|
||||
Assertions.assertEquals("你好,我是张三,我的电话是:13888881111", result);
|
||||
|
||||
final String result2 = StrUtil.format(template, Dict.of().set("name", "张三").set("phone", null));
|
||||
final String result2 = StrUtil.formatByMap(template, Dict.of().set("name", "张三").set("phone", null));
|
||||
Assertions.assertEquals("你好,我是张三,我的电话是:{phone}", result2);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user