I am using JUnit and my situation is as follow:
class A{
public int[] method1(){
...
int res = method2();
...
return intArray;
}
public int method2(){
....
return intA;
}
}
I am trying following to mock the method2()
new MockUp<MockClass>() {
int[] methodToMock() {
int[] mockedResult = {1, 2, 4, 6};
return mockedResult;
}
};
Above code works fine when i use it for another class . But if i want to mock method from same class it doesn't works.
please guide me to find the mocking method in JUnit, to mock method from same class.
Thanks.
method2? Does it contain behavior that is out of scope of the rest of the class? Shold it be moved to some other, if not its own class?spyfor the class under test and configure the alternative behavior formethod2.