### Question:
AttendanceExtractor implements EntityDatedExtract { @Override public void extractEntities(EntityToEdOrgDateCache studentCache) { edOrgExtractHelper.logSecurityEvent(map.getEdOrgs(), EntityNames.ATTENDANCE, this.getClass().getName()); Iterator<Entity> attendances = repo.findEach("attendance", new NeutralQuery()); while (attendances.hasNext()) { Entity attendance = attendances.next(); Map<String, DateTime> studentEdOrgDate = studentCache.getEntriesById((String) attendance.getBody().get("studentId")); for (Map.Entry<String, DateTime> entry: studentEdOrgDate.entrySet()) { DateTime upToDate = entry.getValue(); if (EntityDateHelper.shouldExtract(attendance, upToDate)) { extractor.extractEntity(attendance, map.getExtractFileForEdOrg(entry.getKey()), EntityNames.ATTENDANCE); } } } } AttendanceExtractor(EntityExtractor extractor, ExtractFileMap map, Repository<Entity> repo,
            EdOrgExtractHelper edOrgExtractHelper); @Override void extractEntities(EntityToEdOrgDateCache studentCache);  }### Answer:
@Test public void testWriteOneAttendance() { Mockito.when(mockRepo.findEach(Mockito.eq("attendance"), Mockito.eq(new NeutralQuery()))).thenReturn( Arrays.asList(mockEntity).iterator()); entityBody.put("studentId", "student"); entityBody.put(ParameterConstants.SCHOOL_YEAR, "2010-2011"); extractor.extractEntities(mockCache); Mockito.verify(mockExtractor).extractEntity(Mockito.eq(mockEntity), Mockito.eq(mockFile), Mockito.eq("attendance")); }
@Test public void testWriteManyAttendances() { Mockito.when(mockRepo.findEach(Mockito.eq("attendance"), Mockito.eq(new NeutralQuery()))).thenReturn( Arrays.asList(mockEntity, mockEntity, mockEntity).iterator()); entityBody.put("studentId", "student"); entityBody.put(ParameterConstants.SCHOOL_YEAR, "2010-2011"); extractor.extractEntities(mockCache); Mockito.verify(mockExtractor, Mockito.times(3)).extractEntity(Mockito.eq(mockEntity), Mockito.eq(mockFile), Mockito.eq("attendance")); }
@Test public void testWriteNoAttendances() { Mockito.when(mockRepo.findEach(Mockito.eq("attendance"), Mockito.eq(new NeutralQuery()))).thenReturn( Arrays.asList(mockEntity, mockEntity, mockEntity).iterator()); entityBody.put("studentId", "student"); entityBody.put(ParameterConstants.SCHOOL_YEAR, "2010-2011"); Mockito.when(mockCache.getEntriesById("student")).thenReturn(new HashMap<String, DateTime>()); extractor.extractEntities(mockCache); Mockito.verify(mockExtractor, Mockito.never()).extractEntity(Mockito.eq(mockEntity), Mockito.eq(mockFile), Mockito.eq("attendance")); }
@Test public void testWriteFutureAttendances() { Mockito.when(mockRepo.findEach(Mockito.eq("attendance"), Mockito.eq(new NeutralQuery()))).thenReturn( Arrays.asList(mockEntity, mockEntity, mockEntity).iterator()); entityBody.put("studentId", "student"); entityBody.put(ParameterConstants.SCHOOL_YEAR, "3010-3011"); extractor.extractEntities(mockCache); Mockito.verify(mockExtractor, Mockito.never()).extractEntity(Mockito.eq(mockEntity), Mockito.eq(mockFile), Mockito.eq("attendance")); }