Java 设置this.updateTime,但在运行测试时会引发NullPointerException

Java 设置this.updateTime,但在运行测试时会引发NullPointerException,java,junit,nullpointerexception,this,Java,Junit,Nullpointerexception,This,在我的测试中我有: final MockKeyReader mockReader=(MockApiKeyReader)getKeyReader(); mockReader.setUpdateTime(100L); MockKeyReader有以下方法: public void setUpdateTime(最终长更新时间){ this.updateTime=updateTime; } 我认为是因为setUpdateTime设置了this.updateTime的值,当mockReader.set

在我的测试中我有:

final MockKeyReader mockReader=(MockApiKeyReader)getKeyReader();
mockReader.setUpdateTime(100L);
MockKeyReader
有以下方法:

public void setUpdateTime(最终长更新时间){
this.updateTime=updateTime;
}
我认为是因为
setUpdateTime
设置了
this.updateTime
的值,当
mockReader.setUpdateTime(100L)时这个
的工作原理

这是引发异常的行:

如果(!this.updateTime.equals)(ProductionBlocking
.get(this.keyReader.updateTime)(this.config.configId.toString(),
keyType.PLUSSTAR))){
我刚刚意识到,我正在尝试将两个
长度
.equals()
进行比较。我将行更改为:

if(this.updateTime!=ProductionBlocking
.get(this.keyReader.updateTime)(this.config.configId.toString(),
keyType.PLUSSTAR))){
但是问题仍然存在。
this.updateTime
ProductionBlocking
.get(this.keyReader.updateTime)(this.config.configId.toString(),
keyType.PLUSSTAR))
null

我希望
mockReader.setUpdateTime(100L);
setUpdateTime
中设置
this.updateTime
,但这并没有发生

我觉得我的理解可能不正确

ProductionBlocking
.get(this.keyReader.updateTime)(this.config.configId.toString(),

键类型(PLUSSTAR)
使用接口
ApiKeyReader
并且
MockApiKeyReader
是一个模拟的接口。

这个。updateTime应该等于updateTime而不是LastUpdateTime,或者最好将方法参数重命名为LastUpdateTime。很抱歉,之前已经更改了。错过了最后一个。我已经在查询中修复了这个问题,但仍然存在问题e、 您确定NPE在抛出的MockKeyReader中?可能方法getKeyReader()返回null。可能您可以添加NPE抛出的行问题已用其他信息更新。