| 1210 | |
| 1211 | #[test] |
| 1212 | fn test_multiple_classes_in_file() { |
| 1213 | let mut parser = JavaParser::new(); |
| 1214 | let source = r#" |
| 1215 | public class Main { |
| 1216 | public void run() {} |
| 1217 | } |
| 1218 | |
| 1219 | class Helper { |
| 1220 | void assist() {} |
| 1221 | } |
| 1222 | "#; |
| 1223 | let entities = parser.extract(source, "Main.java"); |
| 1224 | |
| 1225 | assert!( |
| 1226 | entities |
| 1227 | .iter() |
| 1228 | .any(|e| e.name == "Main" && e.kind == EntityKind::Class), |
| 1229 | "Should find Main class" |
| 1230 | ); |
| 1231 | assert!( |
| 1232 | entities |
| 1233 | .iter() |
| 1234 | .any(|e| e.name == "Helper" && e.kind == EntityKind::Class), |
| 1235 | "Should find Helper class" |
| 1236 | ); |
| 1237 | |
| 1238 | let main_class = entities |
| 1239 | .iter() |
| 1240 | .find(|e| e.name == "Main" && e.kind == EntityKind::Class) |
| 1241 | .unwrap(); |
| 1242 | assert!(main_class.exported, "Main should be public"); |
| 1243 | |
| 1244 | let helper_class = entities |
| 1245 | .iter() |
| 1246 | .find(|e| e.name == "Helper" && e.kind == EntityKind::Class) |
| 1247 | .unwrap(); |
| 1248 | assert!( |
| 1249 | !helper_class.exported, |
| 1250 | "Helper should be package-private (not exported)" |
| 1251 | ); |
| 1252 | } |
| 1253 | } |