解决方法:
1.用powermock中的api解决问题,在类中添加:@RunWith(PowerMockRunner.class)
2.如果是第二种情况,则需要重写返回对象的equals方法
把 A a = new A();
PowerMockito.when(a.getTemplate()).thenReturn(template);
@Mock private A a= spy(new A());