How to mock java.util.base64 methods using mockito
How to mock java.util.base64 methods using mockito
I have REST API which returns json response
i am writing test case for the REST api method using mockito
There is a xml response in the json so i am trying to encode the xml string in the json using Base64
My test case throws null pointer exception while executing the Base64.encode line in the REST api method
I cant use powermockito , its not used in the organisation
how can i fix this issue using mockito itself
below is the line of code which throws error
Base64.getEncoder().encodeToString((message)).getBytes(StandardCharsets.UTF_8);
Here message is the xml string .
1 Answer
1
Are you sure you have to embed your XML in your JSON? Perhaps it would make for an easier API if you could transform your XML to JSON and not encode anything?
But, If you're sure you have to have XML nested in JSON, then you should pass Base64.getEncoder()
result as your dependency in your class (Dependency Injection). Then mock it in your test, and pass the mock to your class.
Base64.getEncoder()
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment