Repository navigation
Expand file tree
/
Copy pathtest_java_modern_features.py
More file actions
942 lines (798 loc) · 25.6 KB
/
Copy pathtest_java_modern_features.py
File metadata and controls
942 lines (798 loc) · 25.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
"""
Java modern features parsing testing (Java 8+).
Tests records, sealed classes, pattern matching, switch expressions, text blocks,
var keyword, and other modern Java language features.
"""
from pathlib import Path
from unittest.mock import MagicMock
import pytest
from codebase_rag.graph_updater import GraphUpdater
from codebase_rag.parser_loader import load_parsers
@pytest.fixture
def java_modern_project(temp_repo: Path) -> Path:
"""Create a Java project for testing modern features."""
project_path = temp_repo / "java_modern_test"
project_path.mkdir()
# Create standard Java project structure
(project_path / "src").mkdir()
(project_path / "src" / "main").mkdir()
(project_path / "src" / "main" / "java").mkdir()
(project_path / "src" / "main" / "java" / "com").mkdir()
(project_path / "src" / "main" / "java" / "com" / "example").mkdir()
return project_path
def test_java_records(
java_modern_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test Java record parsing (Java 14+)."""
test_file = (
java_modern_project
/ "src"
/ "main"
/ "java"
/ "com"
/ "example"
/ "Records.java"
)
test_file.write_text(
"""
package com.example;
import java.util.Objects;
// Simple record
public record Point(int x, int y) {}
// Record with validation
public record Person(String name, int age) {
public Person {
if (age < 0) {
throw new IllegalArgumentException("Age cannot be negative");
}
Objects.requireNonNull(name, "Name cannot be null");
}
public String getDisplayName() {
return name.toUpperCase();
}
}
// Record with static methods
public record Rectangle(double width, double height) {
public static Rectangle square(double side) {
return new Rectangle(side, side);
}
public double area() {
return width * height;
}
public boolean isSquare() {
return Double.compare(width, height) == 0;
}
}
// Generic record
public record Pair<T, U>(T first, U second) {
public static <T, U> Pair<T, U> of(T first, U second) {
return new Pair<>(first, second);
}
}
// Record implementing interface
public record Circle(double radius) implements Shape {
@Override
public double area() {
return Math.PI * radius * radius;
}
@Override
public double perimeter() {
return 2 * Math.PI * radius;
}
}
interface Shape {
double area();
double perimeter();
}
// Record with annotations
public record Employee(
@NotNull String name,
@Positive int salary,
@Email String email
) {}
@interface NotNull {}
@interface Positive {}
@interface Email {}
"""
)
parsers, queries = load_parsers()
if "java" not in parsers:
pytest.skip("Java parser not available")
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=java_modern_project,
parsers=parsers,
queries=queries,
)
updater.run()
# Verify records were detected as classes (records are special classes)
project_name = java_modern_project.name
class_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Class"
]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
expected_records = {
f"{project_name}.src.main.java.com.example.Records.Point",
f"{project_name}.src.main.java.com.example.Records.Person",
f"{project_name}.src.main.java.com.example.Records.Rectangle",
f"{project_name}.src.main.java.com.example.Records.Pair",
f"{project_name}.src.main.java.com.example.Records.Circle",
f"{project_name}.src.main.java.com.example.Records.Employee",
}
missing_records = expected_records - created_classes
assert not missing_records, (
f"Missing expected records: {sorted(list(missing_records))}"
)
def test_java_sealed_classes(
java_modern_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test Java sealed classes parsing (Java 17+)."""
test_file = (
java_modern_project
/ "src"
/ "main"
/ "java"
/ "com"
/ "example"
/ "SealedClasses.java"
)
test_file.write_text(
"""
package com.example;
// Sealed class with permitted subclasses
public sealed class Vehicle permits Car, Truck, Motorcycle {
protected final String brand;
protected Vehicle(String brand) {
this.brand = brand;
}
public abstract double fuelEfficiency();
}
// Final implementation
public final class Car extends Vehicle {
private final int doors;
public Car(String brand, int doors) {
super(brand);
this.doors = doors;
}
@Override
public double fuelEfficiency() {
return 30.0; // mpg
}
}
// Non-sealed implementation (can be extended further)
public non-sealed class Truck extends Vehicle {
private final double payloadCapacity;
public Truck(String brand, double payloadCapacity) {
super(brand);
this.payloadCapacity = payloadCapacity;
}
@Override
public double fuelEfficiency() {
return 15.0; // mpg
}
}
// Sealed implementation
public sealed class Motorcycle extends Vehicle permits SportBike, Cruiser {
public Motorcycle(String brand) {
super(brand);
}
@Override
public double fuelEfficiency() {
return 50.0; // mpg
}
}
public final class SportBike extends Motorcycle {
public SportBike(String brand) {
super(brand);
}
}
public final class Cruiser extends Motorcycle {
public Cruiser(String brand) {
super(brand);
}
}
// Sealed interface
public sealed interface Expression permits Value, Addition, Multiplication {
int evaluate();
}
public record Value(int value) implements Expression {
@Override
public int evaluate() {
return value;
}
}
public record Addition(Expression left, Expression right) implements Expression {
@Override
public int evaluate() {
return left.evaluate() + right.evaluate();
}
}
public record Multiplication(Expression left, Expression right) implements Expression {
@Override
public int evaluate() {
return left.evaluate() * right.evaluate();
}
}
"""
)
parsers, queries = load_parsers()
if "java" not in parsers:
pytest.skip("Java parser not available")
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=java_modern_project,
parsers=parsers,
queries=queries,
)
updater.run()
# Verify sealed classes were detected
project_name = java_modern_project.name
all_calls = mock_ingestor.ensure_node_batch.call_args_list
class_calls = [call for call in all_calls if call[0][0] == "Class"]
interface_calls = [call for call in all_calls if call[0][0] == "Interface"]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
created_interfaces = {call[0][1]["qualified_name"] for call in interface_calls}
expected_classes = {
f"{project_name}.src.main.java.com.example.SealedClasses.Vehicle",
f"{project_name}.src.main.java.com.example.SealedClasses.Car",
f"{project_name}.src.main.java.com.example.SealedClasses.Truck",
f"{project_name}.src.main.java.com.example.SealedClasses.Motorcycle",
f"{project_name}.src.main.java.com.example.SealedClasses.SportBike",
f"{project_name}.src.main.java.com.example.SealedClasses.Cruiser",
f"{project_name}.src.main.java.com.example.SealedClasses.Value",
f"{project_name}.src.main.java.com.example.SealedClasses.Addition",
f"{project_name}.src.main.java.com.example.SealedClasses.Multiplication",
}
expected_interfaces = {
f"{project_name}.src.main.java.com.example.SealedClasses.Expression",
}
missing_classes = expected_classes - created_classes
missing_interfaces = expected_interfaces - created_interfaces
assert not missing_classes, (
f"Missing expected sealed classes: {sorted(list(missing_classes))}"
)
assert not missing_interfaces, (
f"Missing expected sealed interfaces: {sorted(list(missing_interfaces))}"
)
def test_java_switch_expressions(
java_modern_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test Java switch expressions parsing (Java 14+)."""
test_file = (
java_modern_project
/ "src"
/ "main"
/ "java"
/ "com"
/ "example"
/ "SwitchExpressions.java"
)
test_file.write_text(
"""
package com.example;
public class SwitchExpressions {
// Classic switch expression with arrow syntax
public String getDayType(String day) {
return switch (day) {
case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" -> "Weekday";
case "Saturday", "Sunday" -> "Weekend";
default -> "Invalid day";
};
}
// Switch expression with yield
public int getQuarter(int month) {
return switch (month) {
case 1, 2, 3 -> {
System.out.println("First quarter");
yield 1;
}
case 4, 5, 6 -> {
System.out.println("Second quarter");
yield 2;
}
case 7, 8, 9 -> {
System.out.println("Third quarter");
yield 3;
}
case 10, 11, 12 -> {
System.out.println("Fourth quarter");
yield 4;
}
default -> {
System.err.println("Invalid month: " + month);
yield -1;
}
};
}
// Switch with enums
public double getDiscount(CustomerType type) {
return switch (type) {
case REGULAR -> 0.0;
case PREMIUM -> 0.1;
case VIP -> 0.2;
case EMPLOYEE -> 0.5;
};
}
// Switch with patterns (conceptual - for future Java versions)
public String processObject(Object obj) {
return switch (obj) {
case String s -> "String: " + s;
case Integer i -> "Integer: " + i;
case Double d -> "Double: " + d;
case null -> "null value";
default -> "Unknown type: " + obj.getClass().getSimpleName();
};
}
// Nested switch expressions
public String complexLogic(int x, int y) {
return switch (x) {
case 1 -> switch (y) {
case 1 -> "both one";
case 2 -> "x=1, y=2";
default -> "x=1, y=" + y;
};
case 2 -> switch (y) {
case 1 -> "x=2, y=1";
case 2 -> "both two";
default -> "x=2, y=" + y;
};
default -> "x=" + x + ", y=" + y;
};
}
// Switch statement (traditional)
public void traditionalSwitch(CustomerType type) {
switch (type) {
case REGULAR:
System.out.println("Regular customer");
break;
case PREMIUM:
System.out.println("Premium customer");
break;
case VIP:
System.out.println("VIP customer");
// fall through
case EMPLOYEE:
System.out.println("Special handling");
break;
default:
System.out.println("Unknown customer type");
}
}
}
enum CustomerType {
REGULAR, PREMIUM, VIP, EMPLOYEE
}
"""
)
parsers, queries = load_parsers()
if "java" not in parsers:
pytest.skip("Java parser not available")
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=java_modern_project,
parsers=parsers,
queries=queries,
)
updater.run()
# Verify the class and enum were detected
project_name = java_modern_project.name
all_calls = mock_ingestor.ensure_node_batch.call_args_list
class_calls = [call for call in all_calls if call[0][0] == "Class"]
enum_calls = [call for call in all_calls if call[0][0] == "Enum"]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
created_enums = {call[0][1]["qualified_name"] for call in enum_calls}
expected_classes = {
f"{project_name}.src.main.java.com.example.SwitchExpressions.SwitchExpressions",
}
expected_enums = {
f"{project_name}.src.main.java.com.example.SwitchExpressions.CustomerType",
}
missing_classes = expected_classes - created_classes
missing_enums = expected_enums - created_enums
assert not missing_classes, (
f"Missing expected classes: {sorted(list(missing_classes))}"
)
assert not missing_enums, f"Missing expected enums: {sorted(list(missing_enums))}"
def test_java_text_blocks(
java_modern_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test Java text blocks parsing (Java 15+)."""
test_file = (
java_modern_project
/ "src"
/ "main"
/ "java"
/ "com"
/ "example"
/ "TextBlocks.java"
)
test_file.write_text(
'''
package com.example;
public class TextBlocks {
// Simple text block
public String getHtmlTemplate() {
return """
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome!</h1>
</body>
</html>
""";
}
// JSON text block
public String getJsonTemplate() {
return """
{
"name": "John Doe",
"age": 30,
"address": {
"street": "123 Main St",
"city": "Anytown",
"zipCode": "12345"
},
"hobbies": ["reading", "swimming", "coding"]
}
""";
}
// SQL text block
public String getSqlQuery() {
return """
SELECT u.name, u.email, p.title
FROM users u
JOIN posts p ON u.id = p.author_id
WHERE u.active = true
AND p.published_date > ?
ORDER BY p.published_date DESC
LIMIT 10
""";
}
// Text block with interpolation-like formatting
public String getFormattedMessage(String name, int age) {
return """
Dear %s,
We are pleased to inform you that your account has been created.
Your age on file is %d years.
Best regards,
The Team
""".formatted(name, age);
}
// Text block with escape sequences
public String getTextWithEscapes() {
return """
This text contains:
- A tab: \\t
- A newline: \\n
- A quote: \\"
- A backslash: \\\\
""";
}
// Concatenated text blocks
public String getCombinedText() {
String header = """
===============
REPORT HEADER
===============
""";
String body = """
Content goes here...
More content...
""";
String footer = """
===============
END OF REPORT
===============
""";
return header + body + footer;
}
// Text block in array
public String[] getTemplates() {
return new String[] {
"""
Template 1:
Hello, World!
""",
"""
Template 2:
Goodbye, World!
""",
"""
Template 3:
See you later!
"""
};
}
}
'''
)
parsers, queries = load_parsers()
if "java" not in parsers:
pytest.skip("Java parser not available")
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=java_modern_project,
parsers=parsers,
queries=queries,
)
updater.run()
# Verify the class was detected despite text blocks
project_name = java_modern_project.name
class_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Class"
]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
expected_classes = {
f"{project_name}.src.main.java.com.example.TextBlocks.TextBlocks",
}
missing_classes = expected_classes - created_classes
assert not missing_classes, (
f"Missing expected classes: {sorted(list(missing_classes))}"
)
def test_java_var_keyword(
java_modern_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test Java var keyword parsing (Java 10+)."""
test_file = (
java_modern_project
/ "src"
/ "main"
/ "java"
/ "com"
/ "example"
/ "VarKeyword.java"
)
test_file.write_text(
"""
package com.example;
import java.util.*;
import java.util.stream.Collectors;
public class VarKeyword {
public void demonstrateVar() {
// Basic var usage
var message = "Hello, World!";
var number = 42;
var decimal = 3.14;
var flag = true;
// Collections with var
var list = new ArrayList<String>();
var map = new HashMap<String, Integer>();
var set = new HashSet<String>();
// Generic type inference
var stringList = List.of("apple", "banana", "cherry");
var numberMap = Map.of("one", 1, "two", 2, "three", 3);
// Complex generic types
var complexMap = new HashMap<String, List<Integer>>();
complexMap.put("numbers", List.of(1, 2, 3, 4, 5));
// Method return types
var result = processData();
var optional = findUser("john");
// Lambda expressions with var
var predicate = (String s) -> s.length() > 5;
var function = (Integer i) -> i * 2;
// Stream operations
var filtered = stringList.stream()
.filter(s -> s.startsWith("a"))
.collect(Collectors.toList());
}
public void varInLoops() {
var numbers = List.of(1, 2, 3, 4, 5);
// Enhanced for loop
for (var num : numbers) {
System.out.println(num);
}
// Traditional for loop
for (var i = 0; i < numbers.size(); i++) {
var element = numbers.get(i);
System.out.println("Index " + i + ": " + element);
}
// Try-with-resources
try (var scanner = new Scanner(System.in)) {
var input = scanner.nextLine();
System.out.println("You entered: " + input);
}
}
public void varWithAnonymousClasses() {
// Anonymous class with var
var runnable = new Runnable() {
@Override
public void run() {
System.out.println("Running...");
}
};
// Anonymous class with complex type
var comparator = new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.length() - s2.length();
}
};
}
// Method with var parameters (Java 11+)
public void processValues(var... values) {
for (var value : values) {
System.out.println("Processing: " + value);
}
}
private String processData() {
return "processed";
}
private Optional<String> findUser(String name) {
return Optional.of("User: " + name);
}
}
"""
)
parsers, queries = load_parsers()
if "java" not in parsers:
pytest.skip("Java parser not available")
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=java_modern_project,
parsers=parsers,
queries=queries,
)
updater.run()
# Verify the class was detected despite var usage
project_name = java_modern_project.name
class_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Class"
]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
expected_classes = {
f"{project_name}.src.main.java.com.example.VarKeyword.VarKeyword",
}
missing_classes = expected_classes - created_classes
assert not missing_classes, (
f"Missing expected classes: {sorted(list(missing_classes))}"
)
def test_java_instanceof_patterns(
java_modern_project: Path,
mock_ingestor: MagicMock,
) -> None:
"""Test Java instanceof pattern matching (Java 16+)."""
test_file = (
java_modern_project
/ "src"
/ "main"
/ "java"
/ "com"
/ "example"
/ "InstanceofPatterns.java"
)
test_file.write_text(
"""
package com.example;
public class InstanceofPatterns {
// Traditional instanceof
public String processObjectTraditional(Object obj) {
if (obj instanceof String) {
String str = (String) obj;
return "String: " + str.toUpperCase();
} else if (obj instanceof Integer) {
Integer num = (Integer) obj;
return "Integer: " + (num * 2);
} else if (obj instanceof Double) {
Double d = (Double) obj;
return "Double: " + String.format("%.2f", d);
}
return "Unknown type";
}
// Pattern matching instanceof (Java 16+)
public String processObjectModern(Object obj) {
if (obj instanceof String str) {
return "String: " + str.toUpperCase();
} else if (obj instanceof Integer num) {
return "Integer: " + (num * 2);
} else if (obj instanceof Double d) {
return "Double: " + String.format("%.2f", d);
}
return "Unknown type";
}
// Complex pattern matching
public boolean isLongString(Object obj) {
return obj instanceof String str && str.length() > 10;
}
public double getNumericValue(Object obj) {
if (obj instanceof Integer i) {
return i.doubleValue();
} else if (obj instanceof Double d) {
return d;
} else if (obj instanceof Float f) {
return f.doubleValue();
} else if (obj instanceof String s && s.matches("\\\\d+")) {
return Double.parseDouble(s);
}
throw new IllegalArgumentException("Cannot convert to numeric value");
}
// Nested instanceof patterns
public String processNestedObject(Object obj) {
if (obj instanceof java.util.List<?> list) {
if (!list.isEmpty() && list.get(0) instanceof String firstElement) {
return "List of strings starting with: " + firstElement;
} else if (!list.isEmpty() && list.get(0) instanceof Integer firstNumber) {
return "List of integers starting with: " + firstNumber;
}
return "Non-empty list of unknown type";
} else if (obj instanceof java.util.Map<?, ?> map) {
if (!map.isEmpty()) {
var firstEntry = map.entrySet().iterator().next();
if (firstEntry.getKey() instanceof String key &&
firstEntry.getValue() instanceof String value) {
return "String map: " + key + " -> " + value;
}
}
return "Map with unknown types";
}
return processObjectModern(obj);
}
// Pattern matching in loops
public void processCollection(java.util.Collection<?> collection) {
for (var item : collection) {
if (item instanceof String str) {
System.out.println("String: " + str.length() + " characters");
} else if (item instanceof Number num) {
System.out.println("Number: " + num.doubleValue());
} else if (item instanceof Boolean bool) {
System.out.println("Boolean: " + bool);
} else {
System.out.println("Other: " + item.getClass().getSimpleName());
}
}
}
// Pattern guards
public String categorizeString(Object obj) {
if (obj instanceof String str) {
if (str.isEmpty()) {
return "Empty string";
} else if (str.length() < 10) {
return "Short string: " + str;
} else if (str.length() < 50) {
return "Medium string (" + str.length() + " chars)";
} else {
return "Long string (" + str.length() + " chars)";
}
}
return "Not a string";
}
}
"""
)
parsers, queries = load_parsers()
if "java" not in parsers:
pytest.skip("Java parser not available")
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=java_modern_project,
parsers=parsers,
queries=queries,
)
updater.run()
# Verify the class was detected
project_name = java_modern_project.name
class_calls = [
call
for call in mock_ingestor.ensure_node_batch.call_args_list
if call[0][0] == "Class"
]
created_classes = {call[0][1]["qualified_name"] for call in class_calls}
expected_classes = {
f"{project_name}.src.main.java.com.example.InstanceofPatterns.InstanceofPatterns",
}
missing_classes = expected_classes - created_classes
assert not missing_classes, (
f"Missing expected classes: {sorted(list(missing_classes))}"
)