[#6] cover the models module with junit tests
All checks were successful
DCO / DCO (pull_request) Successful in 28s

Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
Ori Bruk 2024-08-21 11:12:33 +03:00
parent 5f1d89d407
commit 441d3129dc
34 changed files with 1240 additions and 37 deletions

View file

@ -0,0 +1,57 @@
package info.frostfs.sdk;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class UuidExtensionTest {
private static final UUID TEST_UUID = UUID.fromString("ca70c669-0294-432d-8b83-05fc1475a579");
private static final byte[] TEST_UUID_BYTES =
new byte[]{-54, 112, -58, 105, 2, -108, 67, 45, -117, -125, 5, -4, 20, 117, -91, 121};
@Test
void uuidAsBytes_success() {
//When
var result = UuidExtension.asBytes(TEST_UUID);
//Then
assertThat(result).hasSize(16).containsExactly(TEST_UUID_BYTES);
}
@Test
void uuidAsBytes_givenParamsIsNull() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asBytes(null));
}
@Test
void bytesAsUuid_success() {
//When
var result = UuidExtension.asUuid(TEST_UUID_BYTES);
//Then
assertEquals(TEST_UUID, result);
}
@Test
void bytesAsUuid_givenParamsIsNull() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(null));
}
@Test
void bytesAsUuid_wrongArraySize() {
//Given
var valueLength15 = new byte[]{-54, 112, -58, 105, 2, -108, 67, 45, -117, -125, 5, -4, 20, 117, -91};
var valueLength17 = new byte[]{-54, 112, -58, 105, 2, -108, 67, 45, -117, -125, 5, -4, 20, 117, -91, 121, 12};
//When + Then
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(valueLength15));
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(valueLength17));
}
}