mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
Add extra test case for MathUtils.cast
This commit is contained in:
parent
a0f0262357
commit
5dccd2c38b
@ -18,11 +18,17 @@ import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class MathUtilsTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void sum() {
|
||||
assertEquals(Integer.valueOf(5), MathUtils.sum(2, 3.0));
|
||||
@ -57,6 +63,14 @@ public class MathUtilsTest {
|
||||
checkSame((byte) 1, Byte.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cast_throws_on_unsupported_numbers() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("Unsupported target type");
|
||||
|
||||
checkCast(1, AtomicInteger.class);
|
||||
}
|
||||
|
||||
private static void checkCast(Number value, Class<? extends Number> targetClass) {
|
||||
Number target = MathUtils.cast(value, targetClass);
|
||||
assertSame(targetClass, target.getClass());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user