Public class a {
Public void action () {
....
// Findsomethingthroghclassb logic;
....
}
}
First extract some of the part of the part of B into a protected method into a protected method.
Public class a {
Public void action () {
....
FINDSMETHINGTHROGHCLASSB ();
....
}
Protected void findsomethingthroghclassb () {
// Findsomethingthroghclassb logic;
}
}
Then create a in TestCase
A a = new a () {
Protected void findsomethingthroghclassb () {
Mockit ();
}
}
This can use MOCK directly in the test.
Compared to other methods, this method is smaller for Class A, and does not require new type variables.