mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
!914 针对cn.hutool.core.convert.Convert的toStr方法,增加了测试覆盖
Merge pull request !914 from happycoder/v6-dev
This commit is contained in:
commit
a4bca7715b
@ -42,6 +42,17 @@ public class ConvertTest {
|
|||||||
Assert.assertEquals("aaaa", result);
|
Assert.assertEquals("aaaa", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调取对象的toString方法会抛异常的测试类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
private static class TestExceptionClass {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toStrTest() {
|
public void toStrTest() {
|
||||||
final int a = 1;
|
final int a = 1;
|
||||||
@ -76,6 +87,27 @@ public class ConvertTest {
|
|||||||
Assert.assertEquals("640", result);
|
Assert.assertEquals("640", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toStrTest5() {
|
||||||
|
// 被转化的对象有值,正常转换
|
||||||
|
String a = "aaaa";
|
||||||
|
String aDefaultValue = "aDefault";
|
||||||
|
String aResult = Convert.toStr(a, aDefaultValue);
|
||||||
|
Assert.assertEquals(aResult, a);
|
||||||
|
|
||||||
|
// 被转化的对象为null,返回默认值
|
||||||
|
String b = null;
|
||||||
|
String bDefaultValue = "bDefault";
|
||||||
|
String bResult = Convert.toStr(b, bDefaultValue);
|
||||||
|
Assert.assertEquals(bResult, bDefaultValue);
|
||||||
|
|
||||||
|
// 转换失败,返回默认值
|
||||||
|
TestExceptionClass c = new TestExceptionClass();
|
||||||
|
String cDefaultValue = "cDefault";
|
||||||
|
String cResult = Convert.toStr(c, cDefaultValue);
|
||||||
|
Assert.assertEquals(cResult, cDefaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toIntTest() {
|
public void toIntTest() {
|
||||||
final String a = " 34232";
|
final String a = " 34232";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user