问题描述
我有一个带有自动装配字段和最终方法的抽象超类。此外,还有一个具体的子类,其方法调用超类的最终方法。
抽象超类:
public abstract class AbstractSuper {
@Autowired
protected AuthenticationService authenticationService;
@Autowired
protected JobRepository jobRepository;
public final void startOnsuper() {
test();
}
private void test() {
assert authenticationService != null;
assert jobRepository != null;
}
}
具体实现:
@Component
@requiredArgsConstructor
public class ConcreteImpl extends AbstractSuper {
private final PersonService personService;
public void startOnImpl() {
super.startOnsuper();
}
}
JUnit:
@Autowired
private ConcreteImpl concrete;
@Test
public void startOnImpl() {
concrete.startOnImpl();
}
@Test
public void startOnsuper() {
concrete.startOnsuper();
}
为什么 startOnImpl 测试有效而 startOnSuper 测试失败?为什么我从子类调用方法还是从类外部调用方法很重要?对象的状态不应该是一样的吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)