BAEL-7453 - Add access modifiers to methods and classes. Add Assertions class static import

This commit is contained in:
ICKostiantyn.Ivanov 2024-01-18 14:09:06 +01:00
parent bd1239c699
commit d6f5abfe6a
2 changed files with 20 additions and 18 deletions

View File

@ -1,38 +1,39 @@
package com.baeldung.array.conversions;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.commons.lang3.ArrayUtils;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
class ByteArrayToPrimitiveByteArrayUnitTest {
public class ByteArrayToPrimitiveByteArrayUnitTest {
private static final byte[] EXPECTED_ARRAY_VALUES = {65, 66, 67, 68};
private static final Byte[] BYTE_ARRAY = {65, 66, 67, 68};
@Test
void givenByteArray_whenConvertingUsingByteValue_thenGiveExpectedResult() {
public void givenByteArray_whenConvertingUsingByteValue_thenGiveExpectedResult() {
byte[] newByteArray = new byte[BYTE_ARRAY.length];
for (int i = 0; i < BYTE_ARRAY.length; i++) {
newByteArray[i] = BYTE_ARRAY[i].byteValue();
}
Assertions.assertThat(newByteArray)
assertThat(newByteArray)
.containsExactly(EXPECTED_ARRAY_VALUES);
}
@Test
void givenByteArray_whenConvertingUsingUnboxing_thenGiveExpectedResult() {
public void givenByteArray_whenConvertingUsingUnboxing_thenGiveExpectedResult() {
byte[] newByteArray = new byte[BYTE_ARRAY.length];
for (int i = 0; i < BYTE_ARRAY.length; i++) {
newByteArray[i] = BYTE_ARRAY[i];
}
Assertions.assertThat(newByteArray)
assertThat(newByteArray)
.containsExactly(EXPECTED_ARRAY_VALUES);
}
@Test
void givenByteArray_whenConvertingArrayUtils_thenGiveExpectedResult() {
public void givenByteArray_whenConvertingArrayUtils_thenGiveExpectedResult() {
byte[] newByteArray = ArrayUtils.toPrimitive(BYTE_ARRAY);
Assertions.assertThat(newByteArray)
assertThat(newByteArray)
.containsExactly(EXPECTED_ARRAY_VALUES);
}
}

View File

@ -1,49 +1,50 @@
package com.baeldung.array.conversions;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import org.apache.commons.lang3.ArrayUtils;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
class PrimitiveByteArrayToByteArrayUnitTest {
public class PrimitiveByteArrayToByteArrayUnitTest {
private static final byte[] PRIMITIVE_BYTE_ARRAY = {65, 66, 67, 68};
private static final Byte[] EXPECTED_ARRAY_VALUES = {65, 66, 67, 68};
@Test
void givenPrimitiveByteArray_whenConvertingUsingByteValueOf_thenGiveExpectedResult() {
public void givenPrimitiveByteArray_whenConvertingUsingByteValueOf_thenGiveExpectedResult() {
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
for (int i = 0; i < PRIMITIVE_BYTE_ARRAY.length; i++) {
newByteArray[i] = Byte.valueOf(PRIMITIVE_BYTE_ARRAY[i]);
}
Assertions.assertThat(newByteArray)
assertThat(newByteArray)
.containsExactly(EXPECTED_ARRAY_VALUES);
}
@Test
void givenPrimitiveByteArray_whenConvertingUsingAutoboxing_thenGiveExpectedResult() {
public void givenPrimitiveByteArray_whenConvertingUsingAutoboxing_thenGiveExpectedResult() {
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
for (int i = 0; i < PRIMITIVE_BYTE_ARRAY.length; i++) {
newByteArray[i] = PRIMITIVE_BYTE_ARRAY[i];
}
Assertions.assertThat(newByteArray)
assertThat(newByteArray)
.containsExactly(EXPECTED_ARRAY_VALUES);
}
@Test
void givenPrimitiveByteArray_whenConvertingUsingAutoboxingAndArraysSetAll_thenGiveExpectedResult() {
public void givenPrimitiveByteArray_whenConvertingUsingAutoboxingAndArraysSetAll_thenGiveExpectedResult() {
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
Arrays.setAll(newByteArray, n -> PRIMITIVE_BYTE_ARRAY[n]);
Assertions.assertThat(newByteArray)
assertThat(newByteArray)
.containsExactly(EXPECTED_ARRAY_VALUES);
}
@Test
void givenPrimitiveByteArray_whenConvertingUsingArrayUtils_thenGiveExpectedResult() {
public void givenPrimitiveByteArray_whenConvertingUsingArrayUtils_thenGiveExpectedResult() {
Byte[] newByteArray = ArrayUtils.toObject(PRIMITIVE_BYTE_ARRAY);
Assertions.assertThat(newByteArray)
assertThat(newByteArray)
.containsExactly(EXPECTED_ARRAY_VALUES);
}
}