|
| 1 | +package com.baeldung.abstractnumber; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +public class AbstractNumberUnitTest { |
| 8 | + |
| 9 | + private final static double DOUBLE_VALUE = 9999.999; |
| 10 | + private final static float FLOAT_VALUE = 101.99F; |
| 11 | + private final static long LONG_VALUE = 1000L; |
| 12 | + private final static int INTEGER_VALUE = 100; |
| 13 | + private final static short SHORT_VALUE = 127; |
| 14 | + private final static byte BYTE_VALUE = 120; |
| 15 | + |
| 16 | + @Test |
| 17 | + public void givenDoubleValue_whenShortValueUsed_thenShortValueReturned() { |
| 18 | + Double doubleValue = Double.valueOf(DOUBLE_VALUE); |
| 19 | + assertEquals(9999, doubleValue.shortValue()); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void givenFloatValue_whenByteValueUsed_thenByteValueReturned() { |
| 24 | + Float floatValue = Float.valueOf(FLOAT_VALUE); |
| 25 | + assertEquals(101, floatValue.byteValue()); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void givenLongValue_whenInitValueUsed_thenInitValueReturned() { |
| 30 | + Long longValue = Long.valueOf(LONG_VALUE); |
| 31 | + assertEquals(1000, longValue.intValue()); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void givenIntegerValue_whenLongValueUsed_thenLongValueReturned() { |
| 36 | + Integer integerValue = Integer.valueOf(INTEGER_VALUE); |
| 37 | + assertEquals(100, integerValue.longValue()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void givenShortValue_whenFloatValueUsed_thenFloatValueReturned() { |
| 42 | + Short shortValue = Short.valueOf(SHORT_VALUE); |
| 43 | + assertEquals(127.0F, shortValue.floatValue(), 0); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void givenByteValue_whenDoubleValueUsed_thenDoubleValueReturned() { |
| 48 | + Byte byteValue = Byte.valueOf(BYTE_VALUE); |
| 49 | + assertEquals(120.0, byteValue.doubleValue(), 0); |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments