frostfs-sdk-java/cryptography/src/test/java/info/frostfs/sdk/ArrayHelperTest.java
Bruk Ori c9a54d56fb [#6] cover the cryptography module with junit tests
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
2024-08-28 09:57:53 +00:00

66 lines
1.9 KiB
Java

package info.frostfs.sdk;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ArrayHelperTest {
@Test
void concatTest_success() {
//Given
var startBytes = new byte[]{1, 2, 3, 4, 5};
var endBytes = new byte[]{6, 7, 8, 9};
//When
var result = ArrayHelper.concat(startBytes, endBytes);
//Then
assertThat(startBytes).hasSize(5);
assertThat(endBytes).hasSize(4);
assertThat(result).hasSize(9).startsWith(startBytes).endsWith(endBytes);
}
@Test
void concatTest_endArrayIsEmpty() {
//Given
var startBytes = new byte[]{1, 2, 3, 4, 5};
var endBytes = new byte[]{};
//When
var result = ArrayHelper.concat(startBytes, endBytes);
//Then
assertThat(startBytes).hasSize(5);
assertThat(endBytes).hasSize(0);
assertThat(result).hasSize(5).startsWith(startBytes);
}
@Test
void concatTest_startArrayIsEmpty() {
//Given
var startBytes = new byte[]{};
var endBytes = new byte[]{6, 7, 8, 9};
//When
var result = ArrayHelper.concat(startBytes, endBytes);
//Then
assertThat(startBytes).hasSize(0);
assertThat(endBytes).hasSize(4);
assertThat(result).hasSize(4).startsWith(endBytes);
}
@Test
void concatTest_givenParamsIsNull() {
//Given
var startBytes = new byte[]{1, 2, 3, 4, 5};
var endBytes = new byte[]{6, 7, 8, 9};
//When + Then
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(startBytes, null));
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(null, endBytes));
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(null, null));
}
}