| 841 | |
| 842 | #[test] |
| 843 | fn test_extract_fields() { |
| 844 | let mut parser = JavaParser::new(); |
| 845 | let source = r#" |
| 846 | public class Config { |
| 847 | public static final int MAX_RETRIES = 3; |
| 848 | public static final String API_URL = "https://api.example.com"; |
| 849 | private int timeout; |
| 850 | protected String host; |
| 851 | } |
| 852 | "#; |
| 853 | let entities = parser.extract(source, "Config.java"); |
| 854 | |
| 855 | let max = entities.iter().find(|e| e.name == "MAX_RETRIES"); |
| 856 | assert!(max.is_some(), "Should find MAX_RETRIES"); |
| 857 | assert_eq!( |
| 858 | max.unwrap().kind, |
| 859 | EntityKind::Const, |
| 860 | "static final should be Const" |
| 861 | ); |
| 862 | assert!(max.unwrap().exported); |
| 863 | |
| 864 | let timeout = entities.iter().find(|e| e.name == "timeout"); |
| 865 | assert!(timeout.is_some(), "Should find timeout field"); |
| 866 | assert_eq!( |
| 867 | timeout.unwrap().kind, |
| 868 | EntityKind::Variable, |
| 869 | "non-static field should be Variable" |
| 870 | ); |
| 871 | assert!( |
| 872 | !timeout.unwrap().exported, |
| 873 | "private field should not be exported" |
| 874 | ); |
| 875 | } |
| 876 | |
| 877 | #[test] |
| 878 | fn test_extract_imports() { |