mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
75
hutool-json/src/test/java/IssueI49VZBTest.java
Normal file
75
hutool-json/src/test/java/IssueI49VZBTest.java
Normal file
@@ -0,0 +1,75 @@
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* https://gitee.com/dromara/hutool/issues/I49VZB
|
||||
*/
|
||||
public class IssueI49VZBTest {
|
||||
public enum NBCloudKeyType {
|
||||
/**
|
||||
* 指纹-视频云
|
||||
*/
|
||||
fingerPrint,
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
password,
|
||||
/**
|
||||
* 卡片
|
||||
*/
|
||||
card,
|
||||
/**
|
||||
* 临时密码
|
||||
*/
|
||||
snapKey;
|
||||
|
||||
public static NBCloudKeyType find(String value) {
|
||||
return Stream.of(values()).filter(e -> e.getValue().equalsIgnoreCase(value)).findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
public static NBCloudKeyType downFind(String keyType) {
|
||||
if (fingerPrint.name().equals(keyType.toLowerCase())) {
|
||||
return NBCloudKeyType.fingerPrint;
|
||||
} else {
|
||||
return find(keyType);
|
||||
}
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public static class UPOpendoor {
|
||||
|
||||
private String keyId;
|
||||
private NBCloudKeyType type;
|
||||
private String time;
|
||||
private int result;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBeanTest(){
|
||||
String str = "{type: \"password\"}";
|
||||
final UPOpendoor upOpendoor = JSONUtil.toBean(str, UPOpendoor.class);
|
||||
Assert.assertEquals(NBCloudKeyType.password, upOpendoor.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enumConvertTest(){
|
||||
final NBCloudKeyType type = Convert.toEnum(NBCloudKeyType.class, "snapKey");
|
||||
Assert.assertEquals(NBCloudKeyType.snapKey, type);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user