From 444d747468b80ec2e136cfdedd52dd6baf55155a Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Mon, 15 Jan 2024 22:32:26 +0530 Subject: [PATCH] Add tests for byte to int conversion --- .../ByteToIntConversionUnitTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/bytetoint/ByteToIntConversionUnitTest.java diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/bytetoint/ByteToIntConversionUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/bytetoint/ByteToIntConversionUnitTest.java new file mode 100644 index 0000000000..61217aad6d --- /dev/null +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/bytetoint/ByteToIntConversionUnitTest.java @@ -0,0 +1,45 @@ +package com.baeldung.bytetoint; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class ByteToIntConversionUnitTest { + @Test + public void givenByte_whenUsingTypeCasting_thenConvertToInt() { + byte b = -51; + int result = ByteToIntConversion.usingTypeCasting(b); + assertEquals(-51, result); + } + + @Test + void givenByte_whenUsingIntegerValueOf_thenConvertToInt() { + byte b = -51; + int result = ByteToIntConversion.usingIntegerValueOf(b); + + assertEquals(-51, result); + } + + @Test + void givenByte_whenUsingByteIntValue_thenConvertToInt() { + byte b = -51; + int result = ByteToIntConversion.usingByteIntValue(b); + + assertEquals(-51, result); + } + + @Test + void givenByte_whenUsingMathToIntExact_thenConvertToInt() { + byte b = -51; + int result = ByteToIntConversion.usingMathToIntExact(b); + + assertEquals(-51, result); + } + + @Test + void givenByte_whenUsingByteUnsignedInt_thenConvertToInt() { + byte b = -51; + int result = ByteToIntConversion.usingByteUnsignedInt(b); + + assertEquals(205, result); + } +}