Bird
0
0

Given this test snippet using TestRestTemplate:

medium📝 component behavior Q13 of 15
Spring Boot - Testing Spring Boot Applications
Given this test snippet using TestRestTemplate:
var response = restTemplate.getForEntity("/api/greet", String.class);
System.out.println(response.getStatusCodeValue());
System.out.println(response.getBody());
If the endpoint /api/greet returns HTTP 200 and body "Hello!", what will be printed?
A200\nnull
B404\nNot Found
C500\nInternal Server Error
D200\nHello!
Step-by-Step Solution
Solution:
  1. Step 1: Understand getForEntity behavior

    It sends GET request and returns response with status and body.
  2. Step 2: Match expected endpoint response

    The endpoint returns 200 status and "Hello!" body, so these print exactly.
  3. Final Answer:

    200\nHello! -> Option D
  4. Quick Check:

    Status 200 and body "Hello!" printed [OK]
Quick Trick: Response status and body print as returned by endpoint [OK]
Common Mistakes:
  • Assuming 404 if endpoint not found in test
  • Expecting null body when response is valid
  • Confusing status code with body content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes