Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8348279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:38:41+00:00 2026-06-09T07:38:41+00:00

I’m trying to write a test for my project that lets me know, I

  • 0

I’m trying to write a test for my project that lets me know, I assume via reflection, if the classes I’m testing might call a specific method.

Note the below example code:

class A implements SomeInterface {
    @Override
    public process(B bInstance) {
        if (Math.rand() < 0.5)
            bInstance.thirdPartyCall(param1, param2); //I need this!
    }
}

The class(es) override a method process(…) that might call a method from one of the objects passed into process(). I need my test to find out if the class(es) in question has been coded to include any calls to B(), and what the parameters are. If we can only get the invocation as a string, I will hopefully be able to work with that.

We have all the source code for both the classes that override A() and the class that contains B(), but we need this to be dynamic for future maintenance’s sake. Since we need this to be dynamic, I can’t just create a mock since I won’t know if my mock’s settings will hit the code that calls the methods from bInstance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:38:44+00:00Added an answer on June 9, 2026 at 7:38 am

    You wouldn’t be able to do this via reflection, as broadly speaking reflection can tell you about the signature of classes, but gives you nothing on their implementations.

    In order to do what you’re after, you would need to look through the bytecode, and look at the invokevirtual (or invokestatic for static methods) codes that appear within each method definition. Using this you could build up a sort of dictionary that determines what calls what. (Presumably this is what IDEs rely on for “find usages” functionality.)

    For “standalone” methods you’ve defined yourself, this might be sufficient. However things will get trickier for methods that override or implement methods defined elsewhere – so if you define your own Runnable, or Map subclass for example. It’s not easily possible (maybe even provably impossible) to know what the concrete implementation of a method call will be just from inspecting the bytecode, so you couldn’t say for sure whether your map’s get() would be called, if the caller simply had a reference to Map. Equally, if you do have a Runnable implementation it’s unlikely that your class A will call run directly; that call is likely to come from somewhere within the standard library (e.g. in an ExecutorService or from Thread.start()), so you’d have to build up a very large transitive call map across everything on the classpath, not just your own code.

    Plus of course, to bring it back to your initial point – you wouldn’t be able to detect reflective calls at all. Method.invoke() can call just about anything from a static analysis perspective.


    I think your intent is good, but unless you can find an existing library to use, it won’t be worth the effort to develop this sort of “coverage” metric for your tests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.