MCPcopy Index your code
hub / github.com/ccxt/ccxt / callMethod

Method callMethod

java/tests/src/main/java/tests/BaseTest.java:764–827  ·  view source on GitHub ↗
(
            Object testFiles2,
            Object methodName,
            Object exchange,
            Object... args
    )

Source from the content-addressed store, hash-verified

762
763
764 public static CompletableFuture<Object> callMethod(
765 Object testFiles2,
766 Object methodName,
767 Object exchange,
768 Object... args
769 ) {
770 try {
771 @SuppressWarnings("unchecked")
772 Map<String, Class<?>> testFiles = (Map<String, Class<?>>) testFiles2;
773
774 String key = String.valueOf(methodName);
775 Class<?> testClass = testFiles.get(key);
776 if (testClass == null) {
777 return failedFuture(new IllegalArgumentException("No test class found for key: " + key));
778 }
779
780 // Build argsWithExchange: [exchange, ...args] with List spreading
781 List<Object> argsWithExchange = new ArrayList<>();
782 argsWithExchange.add(exchange);
783
784 if (args != null) {
785 for (Object arg : args) {
786 if (arg == null) continue;
787
788 if (arg instanceof List<?> list) {
789 argsWithExchange.addAll(list);
790 } else {
791 argsWithExchange.add(arg);
792 }
793 }
794 }
795
796 // key "fetchTicker" -> method "testFetchTicker"
797 String javaMethodName = "test" + capitalizeFirst(key);
798
799 Object testInstance = createInstance(testClass);
800
801 Method method = findCompatibleMethod(testClass, javaMethodName, argsWithExchange);
802 if (method == null) {
803 return failedFuture(new NoSuchMethodException(
804 "No compatible method " + javaMethodName + "(...) found on " + testClass.getName()
805 ));
806 }
807 method.setAccessible(true);
808
809 Object result;
810 try {
811 result = method.invoke(testInstance, argsWithExchange.toArray());
812 } catch (Exception e) {
813 // unwrap underlying exception
814 return failedFuture(e);
815 }
816
817 // emulate "await ((Task)res); return null;"
818 if (result instanceof CompletableFuture<?> cf) {
819 return cf.thenApply(ignored -> null);
820 }
821

Callers 1

testMethodMethod · 0.80

Calls 7

failedFutureMethod · 0.95
capitalizeFirstMethod · 0.95
createInstanceMethod · 0.95
findCompatibleMethodMethod · 0.95
getMethod · 0.45
addMethod · 0.45
toArrayMethod · 0.45

Tested by

no test coverage detected