BAEL-6716 - Add expectedEncodedString variable

This commit is contained in:
ICKostiantyn.Ivanov 2024-01-29 13:00:43 +01:00
parent 492adfa40d
commit 11970c9909
2 changed files with 12 additions and 6 deletions

View File

@ -15,16 +15,18 @@ public class DecodeUUIDStringFromBase64Test {
@Test
public void shouldDecodeUUIDUsingByteArrayAndBase64Decoder() {
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
byte[] decodedBytes = Base64.getDecoder()
.decode("UUrxjPeTX8xsDDoxQOfGgw");
.decode(expectedEncodedString);
UUID uuid = convertToUUID(decodedBytes);
assertEquals(originalUUID, uuid);
}
@Test
public void shouldDecodeUUIDUsingByteBufferAndBase64UrlDecoder() {
String expectedEncodedString = "zF-T94zxSlGDxudAMToMbA";
byte[] decodedBytes = Base64.getUrlDecoder()
.decode("zF-T94zxSlGDxudAMToMbA");
.decode(expectedEncodedString);
ByteBuffer byteBuffer = ByteBuffer.wrap(decodedBytes);
long mostSignificantBits = byteBuffer.getLong();
long leastSignificantBits = byteBuffer.getLong();
@ -34,7 +36,8 @@ public class DecodeUUIDStringFromBase64Test {
@Test
public void shouldDecodeUUIDUsingApacheUtils() {
byte[] decodedBytes = decodeBase64("UUrxjPeTX8xsDDoxQOfGgw");
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
byte[] decodedBytes = decodeBase64(expectedEncodedString);
UUID uuid = Conversion.byteArrayToUuid(decodedBytes, 0);
assertEquals(originalUUID, uuid);
}

View File

@ -15,27 +15,30 @@ public class EncodeUUIDToBase64StringTest {
@Test
public void shouldEncodeUUIDUsingByteArrayAndBase64Encoder() {
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
byte[] uuidBytes = convertToByteArray(originalUUID);
String encodedUUID = Base64.getEncoder().withoutPadding()
.encodeToString(uuidBytes);
assertEquals("UUrxjPeTX8xsDDoxQOfGgw", encodedUUID);
assertEquals(expectedEncodedString, encodedUUID);
}
@Test
public void shouldEncodeUUIDUsingByteBufferAndBase64UrlEncoder() {
String expectedEncodedString = "zF-T94zxSlGDxudAMToMbA";
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(originalUUID.getMostSignificantBits());
byteBuffer.putLong(originalUUID.getLeastSignificantBits());
String encodedUUID = Base64.getUrlEncoder().withoutPadding()
.encodeToString(byteBuffer.array());
assertEquals("zF-T94zxSlGDxudAMToMbA", encodedUUID);
assertEquals(expectedEncodedString, encodedUUID);
}
@Test
public void shouldEncodeUUIDUsingApacheUtils() {
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
byte[] bytes = Conversion.uuidToByteArray(originalUUID, new byte[16], 0, 16);
String encodedUUID = encodeBase64URLSafeString(bytes);
assertEquals("UUrxjPeTX8xsDDoxQOfGgw", encodedUUID);
assertEquals(expectedEncodedString, encodedUUID);
}
private byte[] convertToByteArray(UUID uuid) {