Skip to main content
deleted 1 character in body
Source Link
GalAbra
  • 5.2k
  • 5
  • 27
  • 43

I faced similar situation, the problem is given parameter in Mockito.when() block may not be the same as spring generated. I'll explain my case below, hope to help you:

Product product = new Product(..);
Mockito.when(service.addProduct(product)).thenReturn(saveProduct)

When I send a request, spring generates new Project object which has same fields with product but instance is different. That is, Mockito cannot catch when statement. I changed it like below and it's worked:

Mockito.when(service.addProduct(Mockito.any())).thenReturrnthenReturn(savedProduct)

I faced similar situation, the problem is given parameter in Mockito.when() block may not be the same as spring generated. I'll explain my case below, hope to help you:

Product product = new Product(..);
Mockito.when(service.addProduct(product)).thenReturn(saveProduct)

When I send a request, spring generates new Project object which has same fields with product but instance is different. That is, Mockito cannot catch when statement. I changed it like below and it's worked:

Mockito.when(service.addProduct(Mockito.any())).thenReturrn(savedProduct)

I faced similar situation, the problem is given parameter in Mockito.when() block may not be the same as spring generated. I'll explain my case below, hope to help you:

Product product = new Product(..);
Mockito.when(service.addProduct(product)).thenReturn(saveProduct)

When I send a request, spring generates new Project object which has same fields with product but instance is different. That is, Mockito cannot catch when statement. I changed it like below and it's worked:

Mockito.when(service.addProduct(Mockito.any())).thenReturn(savedProduct)
added code highlighting
Source Link
NearHuscarl
  • 83.2k
  • 24
  • 324
  • 294

I faced similar situation, the problem is given parameter in Mockito.when() block may not be the same as spring generated. I'll explain my case below, hope to help you:

Product product = new Product(..);
Mockito.when(service.addProduct(product)).thenReturn(saveProduct)
Product product = new Product(..);
Mockito.when(service.addProduct(product)).thenReturn(saveProduct)

When I send a request, spring generates new Project object which has same fields with product but instance is different. That is, Mockito cannot catch when statement. I changed it like below and it's worked:

Mockito.when(service.addProduct(Mockito.any())).thenReturrn(savedProduct)
Mockito.when(service.addProduct(Mockito.any())).thenReturrn(savedProduct)

I faced similar situation, the problem is given parameter in Mockito.when() block may not be the same as spring generated. I'll explain my case below, hope to help you:

Product product = new Product(..);
Mockito.when(service.addProduct(product)).thenReturn(saveProduct)

When I send a request, spring generates new Project object which has same fields with product but instance is different. That is, Mockito cannot catch when statement. I changed it like below and it's worked:

Mockito.when(service.addProduct(Mockito.any())).thenReturrn(savedProduct)

I faced similar situation, the problem is given parameter in Mockito.when() block may not be the same as spring generated. I'll explain my case below, hope to help you:

Product product = new Product(..);
Mockito.when(service.addProduct(product)).thenReturn(saveProduct)

When I send a request, spring generates new Project object which has same fields with product but instance is different. That is, Mockito cannot catch when statement. I changed it like below and it's worked:

Mockito.when(service.addProduct(Mockito.any())).thenReturrn(savedProduct)
Source Link

I faced similar situation, the problem is given parameter in Mockito.when() block may not be the same as spring generated. I'll explain my case below, hope to help you:

Product product = new Product(..);
Mockito.when(service.addProduct(product)).thenReturn(saveProduct)

When I send a request, spring generates new Project object which has same fields with product but instance is different. That is, Mockito cannot catch when statement. I changed it like below and it's worked:

Mockito.when(service.addProduct(Mockito.any())).thenReturrn(savedProduct)