BAEL-2995 - possible lossy conversion - fixes
This commit is contained in:
parent
b910336c27
commit
e5c3dbb67c
|
@ -64,7 +64,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-numbers</finalName>
|
||||
<finalName>java-numbers-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
|
|
|
@ -9,6 +9,11 @@ public class ConversionTechniquesUnitTest {
|
|||
|
||||
@Test
|
||||
public void testPrimitiveConversion() {
|
||||
|
||||
long longNum = 24;
|
||||
short shortNum = (short) longNum;
|
||||
|
||||
assertEquals(shortNum, 24);
|
||||
|
||||
double doubleNum = 15.6;
|
||||
int integerNum = (int) doubleNum;
|
||||
|
@ -16,17 +21,6 @@ public class ConversionTechniquesUnitTest {
|
|||
assertEquals(integerNum, 15);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapperConversion() {
|
||||
|
||||
Double doubleNum = 10.3;
|
||||
double dbl = doubleNum.doubleValue();
|
||||
int intgr = (int) dbl;
|
||||
Integer intNum = Integer.valueOf(intgr);
|
||||
|
||||
assertTrue(intNum == 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapperToPrimitiveConversion() {
|
||||
|
||||
|
@ -53,4 +47,16 @@ public class ConversionTechniquesUnitTest {
|
|||
|
||||
assertEquals(longNum, 16);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapperConversion() {
|
||||
|
||||
Double doubleNum = 10.3;
|
||||
double dbl = doubleNum.doubleValue(); //unboxing
|
||||
int intgr = (int) dbl; //downcasting
|
||||
Integer intNum = Integer.valueOf(intgr);
|
||||
|
||||
assertTrue(intNum == 10);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue