BAEL-6716 - Add expectedEncodedString variable
This commit is contained in:
parent
492adfa40d
commit
11970c9909
|
@ -15,16 +15,18 @@ public class DecodeUUIDStringFromBase64Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDecodeUUIDUsingByteArrayAndBase64Decoder() {
|
public void shouldDecodeUUIDUsingByteArrayAndBase64Decoder() {
|
||||||
|
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
|
||||||
byte[] decodedBytes = Base64.getDecoder()
|
byte[] decodedBytes = Base64.getDecoder()
|
||||||
.decode("UUrxjPeTX8xsDDoxQOfGgw");
|
.decode(expectedEncodedString);
|
||||||
UUID uuid = convertToUUID(decodedBytes);
|
UUID uuid = convertToUUID(decodedBytes);
|
||||||
assertEquals(originalUUID, uuid);
|
assertEquals(originalUUID, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDecodeUUIDUsingByteBufferAndBase64UrlDecoder() {
|
public void shouldDecodeUUIDUsingByteBufferAndBase64UrlDecoder() {
|
||||||
|
String expectedEncodedString = "zF-T94zxSlGDxudAMToMbA";
|
||||||
byte[] decodedBytes = Base64.getUrlDecoder()
|
byte[] decodedBytes = Base64.getUrlDecoder()
|
||||||
.decode("zF-T94zxSlGDxudAMToMbA");
|
.decode(expectedEncodedString);
|
||||||
ByteBuffer byteBuffer = ByteBuffer.wrap(decodedBytes);
|
ByteBuffer byteBuffer = ByteBuffer.wrap(decodedBytes);
|
||||||
long mostSignificantBits = byteBuffer.getLong();
|
long mostSignificantBits = byteBuffer.getLong();
|
||||||
long leastSignificantBits = byteBuffer.getLong();
|
long leastSignificantBits = byteBuffer.getLong();
|
||||||
|
@ -34,7 +36,8 @@ public class DecodeUUIDStringFromBase64Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDecodeUUIDUsingApacheUtils() {
|
public void shouldDecodeUUIDUsingApacheUtils() {
|
||||||
byte[] decodedBytes = decodeBase64("UUrxjPeTX8xsDDoxQOfGgw");
|
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
|
||||||
|
byte[] decodedBytes = decodeBase64(expectedEncodedString);
|
||||||
UUID uuid = Conversion.byteArrayToUuid(decodedBytes, 0);
|
UUID uuid = Conversion.byteArrayToUuid(decodedBytes, 0);
|
||||||
assertEquals(originalUUID, uuid);
|
assertEquals(originalUUID, uuid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,27 +15,30 @@ public class EncodeUUIDToBase64StringTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldEncodeUUIDUsingByteArrayAndBase64Encoder() {
|
public void shouldEncodeUUIDUsingByteArrayAndBase64Encoder() {
|
||||||
|
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
|
||||||
byte[] uuidBytes = convertToByteArray(originalUUID);
|
byte[] uuidBytes = convertToByteArray(originalUUID);
|
||||||
String encodedUUID = Base64.getEncoder().withoutPadding()
|
String encodedUUID = Base64.getEncoder().withoutPadding()
|
||||||
.encodeToString(uuidBytes);
|
.encodeToString(uuidBytes);
|
||||||
assertEquals("UUrxjPeTX8xsDDoxQOfGgw", encodedUUID);
|
assertEquals(expectedEncodedString, encodedUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldEncodeUUIDUsingByteBufferAndBase64UrlEncoder() {
|
public void shouldEncodeUUIDUsingByteBufferAndBase64UrlEncoder() {
|
||||||
|
String expectedEncodedString = "zF-T94zxSlGDxudAMToMbA";
|
||||||
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
|
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
|
||||||
byteBuffer.putLong(originalUUID.getMostSignificantBits());
|
byteBuffer.putLong(originalUUID.getMostSignificantBits());
|
||||||
byteBuffer.putLong(originalUUID.getLeastSignificantBits());
|
byteBuffer.putLong(originalUUID.getLeastSignificantBits());
|
||||||
String encodedUUID = Base64.getUrlEncoder().withoutPadding()
|
String encodedUUID = Base64.getUrlEncoder().withoutPadding()
|
||||||
.encodeToString(byteBuffer.array());
|
.encodeToString(byteBuffer.array());
|
||||||
assertEquals("zF-T94zxSlGDxudAMToMbA", encodedUUID);
|
assertEquals(expectedEncodedString, encodedUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldEncodeUUIDUsingApacheUtils() {
|
public void shouldEncodeUUIDUsingApacheUtils() {
|
||||||
|
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
|
||||||
byte[] bytes = Conversion.uuidToByteArray(originalUUID, new byte[16], 0, 16);
|
byte[] bytes = Conversion.uuidToByteArray(originalUUID, new byte[16], 0, 16);
|
||||||
String encodedUUID = encodeBase64URLSafeString(bytes);
|
String encodedUUID = encodeBase64URLSafeString(bytes);
|
||||||
assertEquals("UUrxjPeTX8xsDDoxQOfGgw", encodedUUID);
|
assertEquals(expectedEncodedString, encodedUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] convertToByteArray(UUID uuid) {
|
private byte[] convertToByteArray(UUID uuid) {
|
||||||
|
|
Loading…
Reference in New Issue