BAEL-7453 - Add access modifiers to methods and classes. Add Assertions class static import
This commit is contained in:
parent
bd1239c699
commit
d6f5abfe6a
@ -1,38 +1,39 @@
|
|||||||
package com.baeldung.array.conversions;
|
package com.baeldung.array.conversions;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.assertj.core.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
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[] EXPECTED_ARRAY_VALUES = {65, 66, 67, 68};
|
||||||
private static final Byte[] BYTE_ARRAY = {65, 66, 67, 68};
|
private static final Byte[] BYTE_ARRAY = {65, 66, 67, 68};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenByteArray_whenConvertingUsingByteValue_thenGiveExpectedResult() {
|
public void givenByteArray_whenConvertingUsingByteValue_thenGiveExpectedResult() {
|
||||||
byte[] newByteArray = new byte[BYTE_ARRAY.length];
|
byte[] newByteArray = new byte[BYTE_ARRAY.length];
|
||||||
for (int i = 0; i < BYTE_ARRAY.length; i++) {
|
for (int i = 0; i < BYTE_ARRAY.length; i++) {
|
||||||
newByteArray[i] = BYTE_ARRAY[i].byteValue();
|
newByteArray[i] = BYTE_ARRAY[i].byteValue();
|
||||||
}
|
}
|
||||||
Assertions.assertThat(newByteArray)
|
assertThat(newByteArray)
|
||||||
.containsExactly(EXPECTED_ARRAY_VALUES);
|
.containsExactly(EXPECTED_ARRAY_VALUES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenByteArray_whenConvertingUsingUnboxing_thenGiveExpectedResult() {
|
public void givenByteArray_whenConvertingUsingUnboxing_thenGiveExpectedResult() {
|
||||||
byte[] newByteArray = new byte[BYTE_ARRAY.length];
|
byte[] newByteArray = new byte[BYTE_ARRAY.length];
|
||||||
for (int i = 0; i < BYTE_ARRAY.length; i++) {
|
for (int i = 0; i < BYTE_ARRAY.length; i++) {
|
||||||
newByteArray[i] = BYTE_ARRAY[i];
|
newByteArray[i] = BYTE_ARRAY[i];
|
||||||
}
|
}
|
||||||
Assertions.assertThat(newByteArray)
|
assertThat(newByteArray)
|
||||||
.containsExactly(EXPECTED_ARRAY_VALUES);
|
.containsExactly(EXPECTED_ARRAY_VALUES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenByteArray_whenConvertingArrayUtils_thenGiveExpectedResult() {
|
public void givenByteArray_whenConvertingArrayUtils_thenGiveExpectedResult() {
|
||||||
byte[] newByteArray = ArrayUtils.toPrimitive(BYTE_ARRAY);
|
byte[] newByteArray = ArrayUtils.toPrimitive(BYTE_ARRAY);
|
||||||
|
|
||||||
Assertions.assertThat(newByteArray)
|
assertThat(newByteArray)
|
||||||
.containsExactly(EXPECTED_ARRAY_VALUES);
|
.containsExactly(EXPECTED_ARRAY_VALUES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,49 +1,50 @@
|
|||||||
package com.baeldung.array.conversions;
|
package com.baeldung.array.conversions;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.assertj.core.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
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[] PRIMITIVE_BYTE_ARRAY = {65, 66, 67, 68};
|
||||||
private static final Byte[] EXPECTED_ARRAY_VALUES = {65, 66, 67, 68};
|
private static final Byte[] EXPECTED_ARRAY_VALUES = {65, 66, 67, 68};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenPrimitiveByteArray_whenConvertingUsingByteValueOf_thenGiveExpectedResult() {
|
public void givenPrimitiveByteArray_whenConvertingUsingByteValueOf_thenGiveExpectedResult() {
|
||||||
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
|
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
|
||||||
for (int i = 0; i < PRIMITIVE_BYTE_ARRAY.length; i++) {
|
for (int i = 0; i < PRIMITIVE_BYTE_ARRAY.length; i++) {
|
||||||
newByteArray[i] = Byte.valueOf(PRIMITIVE_BYTE_ARRAY[i]);
|
newByteArray[i] = Byte.valueOf(PRIMITIVE_BYTE_ARRAY[i]);
|
||||||
}
|
}
|
||||||
Assertions.assertThat(newByteArray)
|
assertThat(newByteArray)
|
||||||
.containsExactly(EXPECTED_ARRAY_VALUES);
|
.containsExactly(EXPECTED_ARRAY_VALUES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenPrimitiveByteArray_whenConvertingUsingAutoboxing_thenGiveExpectedResult() {
|
public void givenPrimitiveByteArray_whenConvertingUsingAutoboxing_thenGiveExpectedResult() {
|
||||||
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
|
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
|
||||||
for (int i = 0; i < PRIMITIVE_BYTE_ARRAY.length; i++) {
|
for (int i = 0; i < PRIMITIVE_BYTE_ARRAY.length; i++) {
|
||||||
newByteArray[i] = PRIMITIVE_BYTE_ARRAY[i];
|
newByteArray[i] = PRIMITIVE_BYTE_ARRAY[i];
|
||||||
}
|
}
|
||||||
Assertions.assertThat(newByteArray)
|
assertThat(newByteArray)
|
||||||
.containsExactly(EXPECTED_ARRAY_VALUES);
|
.containsExactly(EXPECTED_ARRAY_VALUES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenPrimitiveByteArray_whenConvertingUsingAutoboxingAndArraysSetAll_thenGiveExpectedResult() {
|
public void givenPrimitiveByteArray_whenConvertingUsingAutoboxingAndArraysSetAll_thenGiveExpectedResult() {
|
||||||
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
|
Byte[] newByteArray = new Byte[PRIMITIVE_BYTE_ARRAY.length];
|
||||||
Arrays.setAll(newByteArray, n -> PRIMITIVE_BYTE_ARRAY[n]);
|
Arrays.setAll(newByteArray, n -> PRIMITIVE_BYTE_ARRAY[n]);
|
||||||
|
|
||||||
Assertions.assertThat(newByteArray)
|
assertThat(newByteArray)
|
||||||
.containsExactly(EXPECTED_ARRAY_VALUES);
|
.containsExactly(EXPECTED_ARRAY_VALUES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenPrimitiveByteArray_whenConvertingUsingArrayUtils_thenGiveExpectedResult() {
|
public void givenPrimitiveByteArray_whenConvertingUsingArrayUtils_thenGiveExpectedResult() {
|
||||||
Byte[] newByteArray = ArrayUtils.toObject(PRIMITIVE_BYTE_ARRAY);
|
Byte[] newByteArray = ArrayUtils.toObject(PRIMITIVE_BYTE_ARRAY);
|
||||||
|
|
||||||
Assertions.assertThat(newByteArray)
|
assertThat(newByteArray)
|
||||||
.containsExactly(EXPECTED_ARRAY_VALUES);
|
.containsExactly(EXPECTED_ARRAY_VALUES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user