title: Spring batch:Test case for Tasklet - Key is not appearing in actual class when it is invoked from Test class
body: <p>I am trying to learn Batch and Tasklet.</p>
  
  <p>I am writing a test case for a Tasklet code in spring batch. I am setting a map in my Test class and debug, the actual class is not having the key which I am passing from my test class.</p>
  
  <p><strong>MyEventTasklet.java</strong></p>
  
  <pre><code>public class MyEventTasklet implements Tasklet {
      public RepeatStatus execute (StepContribution contribution, ChunkContext chunkContext){
  
      TreeMap&lt;String, Map&lt;Integer, Set&lt;Student&gt;&gt;&gt; studentMap = chunkContext.getStepContext().getJobExecutionContext().get("keyOfStudentMap");
  
   }   
      }
  </code></pre>
  
  <p><strong>MyEventTaskletTest.java</strong></p>
  
  <pre><code>         @RunWith(MockitoJunitRunner.class)
              public class MyEventTaskletTest{
  
              @Mock
              StepContribution stepContribution;
  
              @Mock
              ChunkContext chunkContext;
  
              @Mock
              StepContext stepContext;
  
              @InjectMocks
              MyEventTasklet myEventTasklet = new MyEventTasklet();
  
              @Test
              public void testExecute(){
  
              TreeMap&lt;String, Map&lt;Integer, Set&lt;Student&gt;&gt;&gt; studentMap = new TreeMap&lt;&gt;();
              Map&lt;Integer, Set&lt;Student&gt;&gt; m2 = new TreeMap&lt;&gt;();
              m2.put(100, createStudentData());
  
              studentMap.put("keyOfStudentMap", m2);
  
              Map&lt;String, Object&gt; map = new TreeMap&lt;&gt;();
              map.put("keyOfStudentMap", new Object());
  
              chunkContext = Mockito.mock(ChunkContext.class);
              stepContribution = Mockito.mock(StepContribution.class);
              stepContext = Mockito.mock(StepContext.class);
  
              Mockito.when(stepContext.getJobExecutionContext()).thenReturn(map);
              Mockito.when(chunkContext.getStepContext()).thenReturn(stepContext);
              Mockito.when(chunkContext.getStepContext().getJobExecutionContext().get("keyOfStudentMap"))
              .thenReturn((TreeMap&lt;String, Map&lt;Integer, Set&lt;Student&gt;&gt;&gt;)studentMap);
  
          // When I am debugging I can see here, the studentMap object which is having something like {keyOfStudentMap={100=[StudentObject]}}, 
  but when I see in actual class it is becoming {100=[StudentObject]}
  
       }
  
   }
  </code></pre>
  
  <p>I am not sure why this is happening, I am doing something wrong? Any kind of help would be highly appreciated. </p>