Spring – how to write mockito JUnit to exchange methods for resttemplate
•
Java
How to write mockito JUnit is as follows:
@Autowired RestTemplate restTemplate; ResponseEntity<?> execute(final String url,HttpMethod httpMethod,httpentity<?> entityRequest,String.class,Map<String,String> urlVariables){ restTemplate.exchange(url,httpMethod,entityRequest,responseType,urlVariables); }
Please help me write how to write
Solution
@RunWith(MockitoJUnitRunner.class)
@RunWith(MockitoJUnitRunner.class) public class ToTestTest { @InjectMocks private YourClass toTest; @Mock private RestTemplate template; @Test public void test() { toTest.execute(Mockito.anyString(),Mockito.any(),Mockito.any()); Mockito.verify(template,Mockito.times(1)) .exchange(Mockito.anyString(),Mockito.<HttpMethod> any(),Mockito.<httpentity<?>> any(),Mockito.<Class<?>> any(),Mockito.<String,String> anyMap()); } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码