春季批处理:如何在那时

时间:2020-05-04 21:10:44

标签: java collections casting spring-batch spring-batch-tasklet

此问题与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>>>的方式进行更改

很抱歉,如果不清楚。我可以根据您的评论更新问题。 :)

1 个答案:

答案 0 :(得分:0)

代替:

chunkContext.getStepContext().getJobExecutionContext()

您需要使用:

chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext()

返回ExecutionContext的实例。

现在无论您在ExecutionContext中键入什么键,都可以在调用get时保持原样,因此可以将其转换为原始类型(在您的情况下为TreeMap<String, Map<Integer, Set<Student>>>)。 / p>