MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_realistic_spring_controller

Function test_realistic_spring_controller

atomic-semantic/src/parsers/java.rs:1090–1197  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1088
1089 #[test]
1090 fn test_realistic_spring_controller() {
1091 let mut parser = JavaParser::new();
1092 let source = r#"
1093package com.example.api;
1094
1095import org.springframework.web.bind.annotation.*;
1096import org.springframework.http.ResponseEntity;
1097import java.util.List;
1098import java.util.Optional;
1099
1100@RestController
1101@RequestMapping("/api/users")
1102public class UserController {
1103
1104 private final UserService userService;
1105
1106 public UserController(UserService userService) {
1107 this.userService = userService;
1108 }
1109
1110 @GetMapping
1111 public ResponseEntity<List<User>> getAllUsers() {
1112 List<User> users = userService.findAll();
1113 return ResponseEntity.ok(users);
1114 }
1115
1116 @GetMapping("/{id}")
1117 public ResponseEntity<User> getUserById(@PathVariable String id) {
1118 Optional<User> user = userService.findById(id);
1119 return user.map(ResponseEntity::ok)
1120 .orElse(ResponseEntity.notFound().build());
1121 }
1122
1123 @PostMapping
1124 public ResponseEntity<User> createUser(@RequestBody User user) {
1125 User created = userService.save(user);
1126 return ResponseEntity.status(201).body(created);
1127 }
1128
1129 @DeleteMapping("/{id}")
1130 public ResponseEntity<Void> deleteUser(@PathVariable String id) {
1131 userService.delete(id);
1132 return ResponseEntity.noContent().build();
1133 }
1134
1135 private void validateUser(User user) {
1136 if (user.getName() == null) {
1137 throw new IllegalArgumentException("Name is required");
1138 }
1139 }
1140}
1141"#;
1142 let entities = parser.extract(source, "UserController.java");
1143 let names: Vec<&str> = entities.iter().map(|e| e.name.as_str()).collect();
1144
1145 // Class
1146 assert!(
1147 names.contains(&"UserController"),

Callers

nothing calls this directly

Calls 6

extractMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
unwrapMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected