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 8974145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:36:53+00:00 2026-06-15T18:36:53+00:00

Hi: Normally you use mock (java agent) to replace an object in the class.

  • 0

Hi: Normally you use mock (java agent) to replace an object in the class.

For example:

public class ClassA{
  public ClassB realObjectB;
  public ClassC realObjectC;


  public void Method1(){
       realObjectC = new ClassC();
       realObjectB =  new ClassB(realObjectC);   
  }     

  ...

  ...   

}

public class ClassB {


      public void ParticularInhereitedMethod(){
          many dependency objects involved...
      }  

} 

of course, ClassB and ClassC have many other dependency, for example connection pool.

When I do testing, may I do:

 public class Mock extends ClassB{        

 @override  
 public class ParticularInhereitedMethod(){
      Make clean codes, no dependency.
 }

}

In test application:

   public class MainClass{

          public static void main(String[] args){
                  ClassA a = new ClassA();
                  ClassM m = new Mock();
                  a.realObjectB = m; 

                  manipulate m;
          }

   }  

Is this above method works in real testing? Why do I have to use Java agent(byte code replacement)?

  • 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-15T18:36:54+00:00Added an answer on June 15, 2026 at 6:36 pm

    I suggest to use a Mockito http://code.google.com/p/mockito/ and Spring injection to resolve your problem.

    With mockito tou can declare the return parameter on an object from the parameters, with spring you can resolve the instance of the object at runtime

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

Sidebar

Related Questions

I normally use Java development and the Google Eclipse plugin, which integrates GoogleAppEngine deploy
I normally use java.lang.ProcessBuilder and java.lang.Process to run external command line programs, and it
We normally use Eclipse for a particular Java project, but recently I imported the
Possible Duplicate: JAX-WS - Map Exceptions to faults I do not normally use java,
For HTTP communications in Java, I normally use the HttpClient library. However, my latest
I normally use this pattern to iterate over object properties: for(var property in object)
In Python/C++, I normally use _(string) for i18n string text. for Java, I use
when I'm using a switch(in Java in this case) I normally use the default
I normally use infinite loop as in the way below: public static boolean start
What is the use of typename associated with a particular class? For example, Point

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.