Bird
0
0

Given the following test code snippet, what will be the HTTP status code in response.getStatusCode() if the endpoint exists and returns successfully?

medium📝 component behavior Q4 of 15
Spring Boot - Testing Spring Boot Applications
Given the following test code snippet, what will be the HTTP status code in response.getStatusCode() if the endpoint exists and returns successfully?
@Autowired
private TestRestTemplate restTemplate;

ResponseEntity response = restTemplate.getForEntity("/api/items/1", String.class);
A200 OK
B404 Not Found
C500 Internal Server Error
D302 Found
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the getForEntity call

    It sends a GET request to /api/items/1 expecting a String response.
  2. Step 2: Consider endpoint existence and success

    If the endpoint exists and processes successfully, the HTTP status is 200 OK.
  3. Final Answer:

    200 OK -> Option A
  4. Quick Check:

    Successful GET request returns 200 OK [OK]
Quick Trick: Successful GET returns 200 OK status code [OK]
Common Mistakes:
  • Assuming 404 when endpoint exists
  • Confusing 500 error with success
  • Mistaking 302 redirect for normal GET

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes