Posts

Showing posts with the label mockito

Eclipse Photon does not resolve imports in test sources

Eclipse Photon does not resolve imports in test sources I have moved to Eclipse Photon with an existing workspace. I have some Maven projects in this workspace. All projects did not have any errors in Eclipse Oxygen. After opening my workspace in Eclipse Photon all test-classes which import org.mockito.Mockito , org.springframework.mock and org.springframework.test have errors. These imports cannot be resolved though Eclipse is aware of them as I can jump into the classes. org.mockito.Mockito org.springframework.mock org.springframework.test Why can Eclipse Photon not resolve these imports? And how can I fix this? 2 Answers 2 If this is really a maven project and you are using matching m2e-version 1.9, it should automatically configure the "Contains test sources."-setting and the related settings correctly. You may have to update the project classpath by right-clicking on the project and...

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 you...