From 86f7514df6911e70db72b02271a083f7a315d7e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Cardo=C5=9F?= <106325528+sodrac@users.noreply.github.com> Date: Wed, 30 Aug 2023 00:56:00 +0300 Subject: [PATCH] BAEL-6819 convert from int to Long in Java (#14671) * BAEL-6819 convert from int to Long in Java * BAEL-6819 update package name --- .../baeldung/inttolong/IntToLongUnitTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/inttolong/IntToLongUnitTest.java diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/inttolong/IntToLongUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/inttolong/IntToLongUnitTest.java new file mode 100644 index 0000000000..bc4109b42a --- /dev/null +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/inttolong/IntToLongUnitTest.java @@ -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); + } +} \ No newline at end of file