package info.frostfs.sdk; import info.frostfs.sdk.exceptions.ValidationFrostFSException; 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(ValidationFrostFSException.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(ValidationFrostFSException.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(ValidationFrostFSException.class, () -> UuidExtension.asUuid(valueLength15)); assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(valueLength17)); } }