Q:

Mock a method inside a constructor of a class

I am new to mockito. Lets say I have a class like this
public class MyClass {
    int a;
    String b;
    public MyClass(int a) {
        this.a = a;
        this.b = draw();
        System.out.println("class is created");
    }

    public String draw() {
        System.out.println("my");
        return "b";
    }

    public void apple() {
        System.out.println("apple");
    }
}

I am writing a JUnit test using Mockito where I am creating a object of the class by using the constructor. Is it possible to mock the draw() method when I am instating the class?

A:

Not clear why you need the Mockito here. This is a solution without Mockito.
In your test create an instance of MyClass with overridden draw() method:
final MyClass myClass = new MyClass() {
    @Override
    public String draw() {
        return "mock data";
    }
}

// Now test your class as you want

