I am trying to write Test for this class (Java Spring Boot): https://github.com/callistaenterprise/blog-microservices/blob/master/microservices/composite/product-composite-service/src/main/java/se/callista/microservices/composite/product/service/ProductCompositeIntegration.java
Specifically, I am trying to Mock this method call:
URI uri = util.getServiceUrl("product");
To do this, I tried to instantiate a Mock of the ServiceUtils object and use the .when and .thenReturn Mock methods.
private ProductCompositeIntegration productIntegration = new ProductCompositeIntegration();
@Autowired
private RestTemplate restTemplate;
@Mock
private ServiceUtils util;
private MockRestServiceServer mockServer;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mockServer = MockRestServiceServer.createServer(restTemplate);
}
@Test
public void myTest() {
URI uri = URI.create("TestUrl");
Mockito.when(util.getServiceUrl("product")).thenReturn(uri);
ResponseEntity<Product> product = productIntegration.getProduct(1);
}
But I am still getting the result of the original object of ServiceUtils instead of the Mocked method call result.
What am I doing wrong?