forked from plusone/plusone-commons
检查并完善 BigDecimals、Numbers、OptionalTools 的单元测试。
parent
37263c6933
commit
1f8036e170
|
@ -27,8 +27,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Slf4j
|
||||
public class BigDecimalsTests {
|
||||
|
||||
// TODO 【优化】 检查测试用例
|
||||
|
||||
@Test
|
||||
void equalsValue_NullValues_ReturnsTrue() {
|
||||
assertTrue(BigDecimals.equalsValue(null, null));
|
||||
|
@ -176,7 +174,8 @@ public class BigDecimalsTests {
|
|||
BigDecimal bd1 = new BigDecimal("10");
|
||||
BigDecimal bd2 = new BigDecimal("20");
|
||||
BigDecimal bd3 = new BigDecimal("30");
|
||||
assertEquals(new BigDecimal("60"), BigDecimals.sum(bd1, bd2, bd3));
|
||||
BigDecimal bd4 = null;
|
||||
assertEquals(new BigDecimal("60"), BigDecimals.sum(bd1, bd2, bd3, bd4));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -192,6 +191,8 @@ public class BigDecimalsTests {
|
|||
|
||||
@Test
|
||||
void of_BlankString_ReturnsZero() {
|
||||
assertEquals(BigDecimal.ZERO, BigDecimals.of(null));
|
||||
assertEquals(BigDecimal.ZERO, BigDecimals.of(""));
|
||||
assertEquals(BigDecimal.ZERO, BigDecimals.of(" "));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
public
|
||||
class NumbersTests {
|
||||
|
||||
// TODO 【优化】 检查测试用例
|
||||
|
||||
@Test
|
||||
public void sum_ShortArray_ReturnsCorrectSum() {
|
||||
short[] numbers = {1, 2, 3, 4};
|
||||
|
|
|
@ -19,6 +19,7 @@ package xyz.zhouxy.plusone.commons.util;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Optional;
|
||||
|
@ -28,11 +29,12 @@ import java.util.OptionalLong;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* {@link OptionalTools} 单元测试
|
||||
*/
|
||||
public
|
||||
class OptionalToolsTests {
|
||||
|
||||
// TODO 【优化】 检查测试用例
|
||||
|
||||
@Test
|
||||
void optionalOf_NullInteger_ReturnsEmptyOptionalInt() {
|
||||
OptionalInt result = OptionalTools.optionalOf((Integer) null);
|
||||
|
@ -112,8 +114,14 @@ class OptionalToolsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void orElseNull_NullOptional_ReturnsNull() {
|
||||
Object result = OptionalTools.orElseNull(Optional.ofNullable(null));
|
||||
void orElseNull_NullOptional_ThrowsNullPointerException() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> OptionalTools.orElseNull(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void orElseNull_EmptyOptional_ReturnsNull() {
|
||||
Object result = OptionalTools.orElseNull(Optional.empty());
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
|
@ -124,7 +132,13 @@ class OptionalToolsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void toInteger_NullOptionalInt_ReturnsNull() {
|
||||
void toInteger_NullOptionalInt_ThrowsNullPointerException() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> OptionalTools.toInteger(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toInteger_EmptyOptionalInt_ReturnsNull() {
|
||||
Integer result = OptionalTools.toInteger(OptionalInt.empty());
|
||||
assertNull(result);
|
||||
}
|
||||
|
@ -136,7 +150,13 @@ class OptionalToolsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void toLong_NullOptionalLong_ReturnsNull() {
|
||||
void toLong_NullOptionalLong_ThrowsNullPointerException() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> OptionalTools.toLong(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toLong_EmptyOptionalLong_ReturnsNull() {
|
||||
Long result = OptionalTools.toLong(OptionalLong.empty());
|
||||
assertNull(result);
|
||||
}
|
||||
|
@ -148,7 +168,13 @@ class OptionalToolsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void toDouble_NullOptionalDouble_ReturnsNull() {
|
||||
void toDouble_NullOptionalDouble_ThrowsNullPointerException() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> OptionalTools.toDouble(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDouble_EmptyOptionalDouble_ReturnsNull() {
|
||||
Double result = OptionalTools.toDouble(OptionalDouble.empty());
|
||||
assertNull(result);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue