BAEL-6819 convert from int to Long in Java (#14671)

* BAEL-6819 convert from int to Long in Java

* BAEL-6819 update package name
This commit is contained in:
Bogdan Cardoş 2023-08-30 00:56:00 +03:00 committed by GitHub
parent 259de2ed39
commit 86f7514df6
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package com.baeldung.inttolong;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class IntToLongUnitTest {
@Test
void whenUsingTheAutoboxing_thenGetTheExpectedLong() {
int intTen = 10;
Long longTen = (long) intTen;
assertEquals(intTen, longTen);
}
@Test
void whenUsingTheValueOf_thenGetTheExpectedLong() {
int intTen = 10;
Long longTen = Long.valueOf(intTen);
assertEquals(intTen, longTen);
}
@Test
void whenUsingTheConstructor_thenGetTheExpectedLong() {
int intTen = 10;
Long longTen = new Long(intTen);
assertEquals(intTen, longTen);
}
@Test
void whenUsingTheParseLong_thenGetTheExpectedLong() {
int intTen = 10;
Long longTen = Long.parseLong(String.valueOf(intTen));
assertEquals(intTen, longTen);
}
}