Java -Integrationstest fehlschlägt bei Falschtypen -FrofReturnValueJava

Java-Forum
Anonymous
 Java -Integrationstest fehlschlägt bei Falschtypen -FrofReturnValue

Post by Anonymous »

Ich habe diesen Test: < /p>

Code: Select all

@Test
public void healthCorollaUp() throws Exception {
ResponseEntity responseEntity = new ResponseEntity(null, HttpStatus.OK);
when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), any(), eq(CorollaResponse.class)))
.thenReturn(responseEntity);
MvcResult result =
mockMvc.perform(get("/actuator/corollahealth")).andExpect(status().isOk()).andReturn();
assertTrue(
result
.getResponse()
.getContentAsString()
.contains(
"Corolla OK"));
}
< /code>
Nach Zeile: < /p>
when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), any(), eq(CartellResponse.class)))
.thenReturn(responseEntity);
< /code>
Ich erhalte einen InvocationTargetException: < /p>

org.mockito.exceptions.misusing.wrongTypeFreturnValue:
Responseentity kann nicht von toString ()
toString () zurückgegeben werden, sollte die Zeichenfolge < /p>

zurückgeben, wenn Sie sich nicht sicher sind, warum Sie über Fehler gelesen werden on. Schriftliche Multi-Thread-Tests. . Es ist sicherer zu Stub -Spione -< /li>
< /ol>

 Mit Doreturn | Throw () Methodenfamilie. Mehr in Javadocs für Mockito.spy () Methode. .isok ()) 
.
Dies geschieht nur, wenn ich den Endpunkt /Actuator /corollahealth < /code> verwende. Wenn ich meinen Code in den Gesundheitsantrieb stecke, funktioniert er. Dies ist mein CorollahealthCheck -Aktuator. Vielleicht liegt das Problem dort. Ich kann es aber nicht sehen.

Code: Select all

@Component
@Endpoint(id = "corollahealth")
public class CorollaHealthCheck {

@Autowired private CorollaIntegration corollaIntegration;

@ReadOperation
public ResponseEntity corollahealth() {
try {
CorollaResponse corollaResponse = corollaIntegration.checkCorolla();
} catch (Exception e) {
return ResponseEntity.badRequest().body("Corolla couldn't be reached.\nIt may be down or there could be some other issue.\nManually check if Corolla is available.");
}
return ResponseEntity.ok("Corolla OK");
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post