Coder17
Coder17

Reputation: 873

How to write a JUnit test for Base64.decodeBase64

Below is my method for which i want to write Junit test case:

public static byte[] getDecodeBase64(JSONObject object,String key) {
        
  return Base64.decodeBase64(object.getString(key));
}

I wrote this:

@Test
    public void testGetDecodeBase64(){
        
        JSONObject test = new JSONObject();
        test.put("clientId", "test");
        
        String value = "[B@[2807bdeb]";
        
        assertEquals(value, JSONUtil.getDecodeBase64(test, "clientId").toString());
        
    }

But each time the value returned by the method is different.

Upvotes: 1

Views: 1185

Answers (2)

Jonathan Schoreels
Jonathan Schoreels

Reputation: 1720

You should use assertArrayEquals to check what's in the array.

Or, if you want to test with String, to convert your byte array into a String with :

byte[] bytes = {...}
String str = new String(bytes, "UTF-8");

Upvotes: 0

Alexandr Ivanov
Alexandr Ivanov

Reputation: 399

toString method of an array returns a string representing the Id of the array.

Upvotes: 1

Related Questions