- class A
- {
- B b;
- public B getB()
- {
- return b;
- }
- public setB(B b)
- {
- this.b=b;
- }
- public String method(parameter) //method of class A
- {
- String str = b.method2();
- return str;
- }
- }
- class YourTest
- {
- public void testMethodShouldReturnExpectedString()
- {
- A a = new A();
- B b = mock(B.class);
- a.setB(b);
- a.method(parameter);
- }
- }