mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
When MathUtils.cast gets a null input, return null
This commit is contained in:
parent
ff1ae7186a
commit
54ddc2fb2e
@ -60,7 +60,7 @@ public final class MathUtils {
|
||||
|
||||
public static <D extends Number> D cast(Number num, Class<D> type) {
|
||||
D rv;
|
||||
if (type.isInstance(num)) {
|
||||
if (num == null || type.isInstance(num)) {
|
||||
rv = type.cast(num);
|
||||
} else if (type.equals(Byte.class)) {
|
||||
rv = type.cast(num.byteValue());
|
||||
|
||||
@ -13,8 +13,7 @@
|
||||
*/
|
||||
package com.querydsl.core.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
@ -63,6 +62,12 @@ public class MathUtilsTest {
|
||||
checkSame((byte) 1, Byte.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cast_returns_null_when_input_is_null() {
|
||||
Integer result = MathUtils.cast(null, Integer.class);
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cast_throws_on_unsupported_numbers() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user