Skip to content

Commit 48f5af2

Browse files
committed
ByteArrayToStringAdapter tests
1 parent c576ef8 commit 48f5af2

File tree

4 files changed

+61
-6
lines changed

4 files changed

+61
-6
lines changed

src/main/java/com/adyen/model/binlookup/DSPublicKeyDetail.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import java.util.Objects;
2424

25-
import com.adyen.serializer.ByteArrayToStringTypeAdapter;
25+
import com.adyen.serializer.ByteArrayToStringAdapter;
2626
import com.google.gson.annotations.JsonAdapter;
2727
import com.google.gson.annotations.SerializedName;
2828

@@ -39,7 +39,7 @@ public class DSPublicKeyDetail {
3939
private String directoryServerId = null;
4040

4141
@SerializedName("publicKey")
42-
@JsonAdapter(ByteArrayToStringTypeAdapter.class)
42+
@JsonAdapter(ByteArrayToStringAdapter.class)
4343
private byte[] publicKey = null;
4444

4545
public DSPublicKeyDetail brand(String brand) {

src/main/java/com/adyen/model/checkout/ThreeDSecureData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.io.IOException;
2525
import java.util.Objects;
2626

27-
import com.adyen.serializer.ByteArrayToStringTypeAdapter;
27+
import com.adyen.serializer.ByteArrayToStringAdapter;
2828
import com.google.gson.TypeAdapter;
2929
import com.google.gson.annotations.JsonAdapter;
3030
import com.google.gson.annotations.SerializedName;
@@ -39,7 +39,7 @@ public class ThreeDSecureData {
3939
@SerializedName("authenticationResponse")
4040
private AuthenticationResponseEnum authenticationResponse = null;
4141
@SerializedName("cavv")
42-
@JsonAdapter(ByteArrayToStringTypeAdapter.class)
42+
@JsonAdapter(ByteArrayToStringAdapter.class)
4343
private byte[] cavv = null;
4444
@SerializedName("cavvAlgorithm")
4545
private String cavvAlgorithm = null;
@@ -50,7 +50,7 @@ public class ThreeDSecureData {
5050
@SerializedName("threeDSVersion")
5151
private String threeDSVersion = null;
5252
@SerializedName("xid")
53-
@JsonAdapter(ByteArrayToStringTypeAdapter.class)
53+
@JsonAdapter(ByteArrayToStringAdapter.class)
5454
private byte[] xid = null;
5555
@SerializedName("dsTransID")
5656
private String dsTransID = null;

src/main/java/com/adyen/serializer/ByteArrayToStringTypeAdapter.java renamed to src/main/java/com/adyen/serializer/ByteArrayToStringAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import java.lang.reflect.Type;
3333

34-
public class ByteArrayToStringTypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
34+
public class ByteArrayToStringAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
3535
public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
3636
return json.getAsString().getBytes();
3737
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* ######
3+
* ######
4+
* ############ ####( ###### #####. ###### ############ ############
5+
* ############# #####( ###### #####. ###### ############# #############
6+
* ###### #####( ###### #####. ###### ##### ###### ##### ######
7+
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
8+
* ###### ###### #####( ###### #####. ###### ##### ##### ######
9+
* ############# ############# ############# ############# ##### ######
10+
* ############ ############ ############# ############ ##### ######
11+
* ######
12+
* #############
13+
* ############
14+
*
15+
* Adyen Java API Library
16+
*
17+
* Copyright (c) 2019 Adyen B.V.
18+
* This file is open source and available under the MIT license.
19+
* See the LICENSE file for more info.
20+
*/
21+
package com.adyen.serializer;
22+
23+
import com.google.gson.JsonElement;
24+
import com.google.gson.JsonPrimitive;
25+
import org.apache.commons.codec.binary.Base64;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
import org.mockito.junit.MockitoJUnitRunner;
29+
30+
import static org.junit.Assert.assertArrayEquals;
31+
import static org.junit.Assert.assertEquals;
32+
33+
@RunWith(MockitoJUnitRunner.class)
34+
public class ByteArrayToStringAdapterTest {
35+
36+
@Test
37+
public void testSerialize() {
38+
ByteArrayToStringAdapter adapter = new ByteArrayToStringAdapter();
39+
byte[] base64Bytes = Base64.encodeBase64("Bytes-To-Be-Encoded".getBytes());
40+
41+
JsonElement serializedElement = adapter.serialize(base64Bytes, null, null);
42+
assertEquals("Qnl0ZXMtVG8tQmUtRW5jb2RlZA==", serializedElement.getAsString());
43+
}
44+
45+
@Test
46+
public void testDeserialize() {
47+
ByteArrayToStringAdapter adapter = new ByteArrayToStringAdapter();
48+
byte[] base64Bytes = Base64.encodeBase64("Bytes-To-Be-Encoded".getBytes());
49+
50+
JsonElement element = new JsonPrimitive("Qnl0ZXMtVG8tQmUtRW5jb2RlZA==");
51+
byte[] deserializedBytes = adapter.deserialize(element, null, null);
52+
53+
assertArrayEquals(deserializedBytes, base64Bytes);
54+
}
55+
}

0 commit comments

Comments
 (0)