| 1065 | |
| 1066 | #[test] |
| 1067 | fn test_realistic_spring_controller() { |
| 1068 | let mut parser = JavaParser::new(); |
| 1069 | let source = r#" |
| 1070 | package com.example.api; |
| 1071 | |
| 1072 | import org.springframework.web.bind.annotation.*; |
| 1073 | import org.springframework.http.ResponseEntity; |
| 1074 | import java.util.List; |
| 1075 | import java.util.Optional; |
| 1076 | |
| 1077 | @RestController |
| 1078 | @RequestMapping("/api/users") |
| 1079 | public class UserController { |
| 1080 | |
| 1081 | private final UserService userService; |
| 1082 | |
| 1083 | public UserController(UserService userService) { |
| 1084 | this.userService = userService; |
| 1085 | } |
| 1086 | |
| 1087 | @GetMapping |
| 1088 | public ResponseEntity<List<User>> getAllUsers() { |
| 1089 | List<User> users = userService.findAll(); |
| 1090 | return ResponseEntity.ok(users); |
| 1091 | } |
| 1092 | |
| 1093 | @GetMapping("/{id}") |
| 1094 | public ResponseEntity<User> getUserById(@PathVariable String id) { |
| 1095 | Optional<User> user = userService.findById(id); |
| 1096 | return user.map(ResponseEntity::ok) |
| 1097 | .orElse(ResponseEntity.notFound().build()); |
| 1098 | } |
| 1099 | |
| 1100 | @PostMapping |
| 1101 | public ResponseEntity<User> createUser(@RequestBody User user) { |
| 1102 | User created = userService.save(user); |
| 1103 | return ResponseEntity.status(201).body(created); |
| 1104 | } |
| 1105 | |
| 1106 | @DeleteMapping("/{id}") |
| 1107 | public ResponseEntity<Void> deleteUser(@PathVariable String id) { |
| 1108 | userService.delete(id); |
| 1109 | return ResponseEntity.noContent().build(); |
| 1110 | } |
| 1111 | |
| 1112 | private void validateUser(User user) { |
| 1113 | if (user.getName() == null) { |
| 1114 | throw new IllegalArgumentException("Name is required"); |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | "#; |
| 1119 | let entities = parser.extract(source, "UserController.java"); |
| 1120 | let names: Vec<&str> = entities.iter().map(|e| e.name.as_str()).collect(); |
| 1121 | |
| 1122 | // Class |
| 1123 | assert!( |
| 1124 | names.contains(&"UserController"), |