Add tests for byte to int conversion

This commit is contained in:
anujgaud 2024-01-15 22:32:26 +05:30 committed by GitHub
parent 84530dd8bb
commit 444d747468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 0 deletions

View File

@ -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);
}
}