此问题与This有关。为什么我在这里问而不更新问题,因为这可能是有帮助的问题,并且与我之前提出的问题无关。
在Test类中,我如何转换以下实现:
可以说我有这样的地图:TreeMap<String, Map<Integer, Set<Student>>>
我想在我的Test类中将默认的chunkContext.getStepContext().getJobExecutionContext()
转换为Map<String, Object>
到TreeMap<String, Map<Integer, Set<Student>>>
。
现有实现为:
Mockito.when(chunkContext.getStepContext().getJobExecutionContext().get("keyOfStudentMap"))
.thenReturn((TreeMap<String, Map<Integer, Set<Student>>>)studentMap);
当我将鼠标悬停在getJobExecutionContext()
上时,它显示Map<String, Object>
,并希望以可以更改为TreeMap<String, Map<Integer, Set<Student>>>
的方式进行更改
很抱歉,如果不清楚。我可以根据您的评论更新问题。 :)
答案 0 :(得分:0)
代替:
chunkContext.getStepContext().getJobExecutionContext()
您需要使用:
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext()
返回ExecutionContext
的实例。
现在无论您在ExecutionContext
中键入什么键,都可以在调用get
时保持原样,因此可以将其转换为原始类型(在您的情况下为TreeMap<String, Map<Integer, Set<Student>>>
)。 / p>