@@ -484,6 +484,7 @@ def test_get_all_classes(test_fixture, analysis_json_fixture):
484484 eager_analysis = False ,
485485 target_files = None ,
486486 )
487+
487488 all_methods = code_analyzer .get_all_classes ()
488489 assert all_methods is not None
489490 assert isinstance (all_methods , Dict )
@@ -507,6 +508,7 @@ def test_get_class(test_fixture, analysis_json_fixture):
507508 eager_analysis = False ,
508509 target_files = None ,
509510 )
511+
510512 class_info = code_analyzer .get_class ("com.ibm.websphere.samples.daytrader.TradeAction" )
511513 assert class_info is not None
512514 assert isinstance (class_info , JType )
@@ -531,7 +533,6 @@ def test_get_method(test_fixture, analysis_json_fixture):
531533 target_files = None ,
532534 )
533535
534- # Call without using symbol table
535536 method = code_analyzer .get_method ("com.ibm.websphere.samples.daytrader.TradeAction" , "getQuote(String)" )
536537 assert method is not None
537538 assert isinstance (method , JCallable )
@@ -556,7 +557,6 @@ def test_get_java_file(test_fixture, analysis_json_fixture):
556557 target_files = None ,
557558 )
558559
559- # Call without using symbol table
560560 java_file = code_analyzer .get_java_file ("com.ibm.websphere.samples.daytrader.TradeAction" )
561561 assert java_file is not None
562562 assert isinstance (java_file , str )
@@ -588,7 +588,6 @@ def test_get_all_methods_in_class(test_fixture, analysis_json_fixture):
588588 target_files = None ,
589589 )
590590
591- # Call without using symbol table
592591 all_methods = code_analyzer .get_all_methods_in_class ("com.ibm.websphere.samples.daytrader.TradeAction" )
593592 assert all_methods is not None
594593 assert isinstance (all_methods , Dict )
@@ -614,7 +613,6 @@ def test_get_all_constructors(test_fixture, analysis_json_fixture):
614613 target_files = None ,
615614 )
616615
617- # Call without using symbol table
618616 all_constructors = code_analyzer .get_all_constructors ("com.ibm.websphere.samples.daytrader.TradeAction" )
619617 assert all_constructors is not None
620618 assert isinstance (all_constructors , Dict )
@@ -640,7 +638,6 @@ def test_get_all_sub_classes(test_fixture, analysis_json_fixture):
640638 target_files = None ,
641639 )
642640
643- # Call without using symbol table
644641 all_subclasses = code_analyzer .get_all_sub_classes ("com.ibm.websphere.samples.daytrader.TradeAction" )
645642 assert all_subclasses is not None
646643 assert isinstance (all_subclasses , Dict )
@@ -665,12 +662,17 @@ def test_get_all_fields(test_fixture, analysis_json_fixture):
665662 target_files = None ,
666663 )
667664
668- # Call without using symbol table
669665 all_fields = code_analyzer .get_all_fields ("com.ibm.websphere.samples.daytrader.TradeAction" )
670666 assert all_fields is not None
671667 assert isinstance (all_fields , List )
672668 assert len (all_fields ) > 0
673669
670+ # Handle get fields for class not found
671+ all_fields = code_analyzer .get_all_fields ("com.not.Found" )
672+ assert all_fields is not None
673+ assert isinstance (all_fields , List )
674+ assert len (all_fields ) == 0
675+
674676
675677def test_get_all_nested_classes (test_fixture , analysis_json_fixture ):
676678 """It should return all of the nested classes for a class"""
@@ -691,7 +693,186 @@ def test_get_all_nested_classes(test_fixture, analysis_json_fixture):
691693 target_files = None ,
692694 )
693695
694- # Call without using symbol table
695696 all_nested_classes = code_analyzer .get_all_nested_classes ("com.ibm.websphere.samples.daytrader.TradeAction" )
696697 assert all_nested_classes is not None
697698 assert isinstance (all_nested_classes , List )
699+
700+ # Handle class not found
701+ all_nested_classes = code_analyzer .get_all_nested_classes ("com.not.Found" )
702+ assert all_nested_classes is not None
703+ assert isinstance (all_nested_classes , List )
704+ assert len (all_nested_classes ) == 0
705+
706+
707+ def test_get_extended_classes (test_fixture , analysis_json_fixture ):
708+ """It should return all of the extended classes for a class"""
709+ # Get a known good analysis file
710+ analysis_json = get_analysis_json (analysis_json_fixture )
711+
712+ # Patch subprocess so that it does not run codeanalyzer
713+ with patch ("cldk.analysis.java.codeanalyzer.codeanalyzer.subprocess.run" ) as run_mock :
714+ run_mock .return_value = MagicMock (stdout = analysis_json , returncode = 0 )
715+ code_analyzer = JCodeanalyzer (
716+ project_dir = test_fixture ,
717+ source_code = None ,
718+ analysis_backend_path = None ,
719+ analysis_json_path = None ,
720+ analysis_level = AnalysisLevel .call_graph ,
721+ use_graalvm_binary = False ,
722+ eager_analysis = False ,
723+ target_files = None ,
724+ )
725+
726+ all_extended_classes = code_analyzer .get_extended_classes ("com.ibm.websphere.samples.daytrader.TradeAction" )
727+ assert all_extended_classes is not None
728+ assert isinstance (all_extended_classes , List )
729+
730+ # Handle class not found
731+ all_extended_classes = code_analyzer .get_extended_classes ("com.not.Found" )
732+ assert all_extended_classes is not None
733+ assert isinstance (all_extended_classes , List )
734+ assert len (all_extended_classes ) == 0
735+
736+
737+ def test_get_implemented_interfaces (test_fixture , analysis_json_fixture ):
738+ """It should return all of the implemented interfaces for a class"""
739+ # Get a known good analysis file
740+ analysis_json = get_analysis_json (analysis_json_fixture )
741+
742+ # Patch subprocess so that it does not run codeanalyzer
743+ with patch ("cldk.analysis.java.codeanalyzer.codeanalyzer.subprocess.run" ) as run_mock :
744+ run_mock .return_value = MagicMock (stdout = analysis_json , returncode = 0 )
745+ code_analyzer = JCodeanalyzer (
746+ project_dir = test_fixture ,
747+ source_code = None ,
748+ analysis_backend_path = None ,
749+ analysis_json_path = None ,
750+ analysis_level = AnalysisLevel .call_graph ,
751+ use_graalvm_binary = False ,
752+ eager_analysis = False ,
753+ target_files = None ,
754+ )
755+
756+ # Call without using symbol table
757+ all_interfaces = code_analyzer .get_implemented_interfaces ("com.ibm.websphere.samples.daytrader.TradeAction" )
758+ assert all_interfaces is not None
759+ assert isinstance (all_interfaces , List )
760+
761+ # Handle class not found
762+ all_interfaces = code_analyzer .get_implemented_interfaces ("com.not.Found" )
763+ assert all_interfaces is not None
764+ assert isinstance (all_interfaces , List )
765+ assert len (all_interfaces ) == 0
766+
767+
768+ def test_get_class_call_graph_using_symbol_table (test_fixture , analysis_json_fixture ):
769+ """It should return the call graph using the symbol table"""
770+ # Get a known good analysis file
771+ analysis_json = get_analysis_json (analysis_json_fixture )
772+
773+ # Patch subprocess so that it does not run codeanalyzer
774+ with patch ("cldk.analysis.java.codeanalyzer.codeanalyzer.subprocess.run" ) as run_mock :
775+ run_mock .return_value = MagicMock (stdout = analysis_json , returncode = 0 )
776+ code_analyzer = JCodeanalyzer (
777+ project_dir = test_fixture ,
778+ source_code = None ,
779+ analysis_backend_path = None ,
780+ analysis_json_path = None ,
781+ analysis_level = AnalysisLevel .symbol_table ,
782+ use_graalvm_binary = False ,
783+ eager_analysis = False ,
784+ target_files = None ,
785+ )
786+
787+ # TODO: The code seems to be broken for this case
788+ # # Call with method signature
789+ # all_call_graph = code_analyzer.get_class_call_graph_using_symbol_table("com.ibm.websphere.samples.daytrader.TradeAction", "getQuote(String)")
790+ # assert all_call_graph is not None
791+ # assert isinstance(all_call_graph, List)
792+
793+ # Call without method signature
794+ all_call_graph = code_analyzer .get_class_call_graph_using_symbol_table ("com.ibm.websphere.samples.daytrader.TradeAction" , None )
795+ assert all_call_graph is not None
796+ assert isinstance (all_call_graph , List )
797+
798+
799+ def test_get_class_call_graph (test_fixture , analysis_json_fixture ):
800+ """It should return the call graph"""
801+ # Get a known good analysis file
802+ analysis_json = get_analysis_json (analysis_json_fixture )
803+
804+ # Patch subprocess so that it does not run codeanalyzer
805+ with patch ("cldk.analysis.java.codeanalyzer.codeanalyzer.subprocess.run" ) as run_mock :
806+ run_mock .return_value = MagicMock (stdout = analysis_json , returncode = 0 )
807+ code_analyzer = JCodeanalyzer (
808+ project_dir = test_fixture ,
809+ source_code = None ,
810+ analysis_backend_path = None ,
811+ analysis_json_path = None ,
812+ analysis_level = AnalysisLevel .call_graph ,
813+ use_graalvm_binary = False ,
814+ eager_analysis = False ,
815+ target_files = None ,
816+ )
817+
818+ # Call with method signature
819+ class_call_graph = code_analyzer .get_class_call_graph ("com.ibm.websphere.samples.daytrader.TradeAction" , "getQuote(String)" )
820+ assert class_call_graph is not None
821+ assert isinstance (class_call_graph , List )
822+
823+ # Call without method signature
824+ class_call_graph = code_analyzer .get_class_call_graph ("com.ibm.websphere.samples.daytrader.TradeAction" , None )
825+ assert class_call_graph is not None
826+ assert isinstance (class_call_graph , List )
827+
828+
829+ def test_get_all_entry_point_methods (test_fixture , analysis_json_fixture ):
830+ """It should return the all of the entry point methods"""
831+ # Get a known good analysis file
832+ analysis_json = get_analysis_json (analysis_json_fixture )
833+
834+ # Patch subprocess so that it does not run codeanalyzer
835+ with patch ("cldk.analysis.java.codeanalyzer.codeanalyzer.subprocess.run" ) as run_mock :
836+ run_mock .return_value = MagicMock (stdout = analysis_json , returncode = 0 )
837+ code_analyzer = JCodeanalyzer (
838+ project_dir = test_fixture ,
839+ source_code = None ,
840+ analysis_backend_path = None ,
841+ analysis_json_path = None ,
842+ analysis_level = AnalysisLevel .call_graph ,
843+ use_graalvm_binary = False ,
844+ eager_analysis = False ,
845+ target_files = None ,
846+ )
847+
848+ # Call with method signature
849+ entry_point_methods = code_analyzer .get_all_entry_point_methods ()
850+ assert entry_point_methods is not None
851+ assert isinstance (entry_point_methods , Dict )
852+ assert len (entry_point_methods ) > 0
853+
854+
855+ def test_get_all_entry_point_classes (test_fixture , analysis_json_fixture ):
856+ """It should return the all of the entry point classes"""
857+ # Get a known good analysis file
858+ analysis_json = get_analysis_json (analysis_json_fixture )
859+
860+ # Patch subprocess so that it does not run codeanalyzer
861+ with patch ("cldk.analysis.java.codeanalyzer.codeanalyzer.subprocess.run" ) as run_mock :
862+ run_mock .return_value = MagicMock (stdout = analysis_json , returncode = 0 )
863+ code_analyzer = JCodeanalyzer (
864+ project_dir = test_fixture ,
865+ source_code = None ,
866+ analysis_backend_path = None ,
867+ analysis_json_path = None ,
868+ analysis_level = AnalysisLevel .call_graph ,
869+ use_graalvm_binary = False ,
870+ eager_analysis = False ,
871+ target_files = None ,
872+ )
873+
874+ # Call with method signature
875+ entry_point_classes = code_analyzer .get_all_entry_point_classes ()
876+ assert entry_point_classes is not None
877+ assert isinstance (entry_point_classes , Dict )
878+ assert len (entry_point_classes ) > 0
0 commit comments