I created a utility method TwitterUtil.encodeConsumerKeyAndSecret() to return the encoded credentials needed for Twitter's application-only authentication flow. However, when testing my method using the values in Twitter's example, the Apex test fails with the following message:

System.AssertException: Assertion Failed: Expected: eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJnNmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw, Actual: eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJnNmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw==

The entire process worked beautifully except for the presence of the "==" characters at the end of the base64-encoded value returned by my method. All I'm doing is using EncodingUtil.urlEncode() and EncodingUtil.base64Encode() to transform the consumer key and secret, so what is the reason for my method returning the extra "==" characters?

1 Answer 1


Turns out this is a newbie copy/paste error. I double-clicked the final value on Twitter's documentation page to select it, so that I could copy the value and paste it into my Apex test.

enter image description here

However, double-clicking the value in Chrome selected everything except for the final two "==" characters.

enter image description here

So, basically, the test failure was caused by me not copying the correct value from the API docs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .