1
Hello,
The title got a little fuzzy, but come on. I have the class below:
public class ClasseA {
    public static final int constA = ClasseB.metodoB();
    public int metodoA(){
        System.out.println("Passei no metodo A");
        return 2;
    }
}
I would like to mock the method, but I cannot, because it always calls the B method.
My Test Class:
public class TestesClasses {
    @Mock
    private ClasseA classeA;
    @Before
    public void setUp(){
        MockitoAnnotations.initMocks(this);
    }
    @Test
    public void testando(){
        Mockito.when(classeA.metodoA()).thenReturn(1);
        int retorno = classeA.metodoA();
        System.out.println("Retorno "+retorno);
    }
}
I want to mock tmb the B method, as if I wanted to mock almost the entire class. I’ve tried with mockite, powermock, etc and it doesn’t work... If anyone can help me and put how you did the test class, I really appreciate it!!!!
I don’t understand. You want the mock of the object of
ClasseA? Or want to mock the static method ofClasseB?– Jefferson Quesado
I want to mock the Class A method, but when I declare: @Mock Private Classea classeA; it calls the method B... that tmb want to mock
– Fernando Schelb
Your question gave me this doubt: https://answall.com/q/269196/64969
– Jefferson Quesado