### Question:
CreateCandidatesMapper implements MapFunction<ParsedWikiDocument, WikiDocumentOutput> { public static int closestIdentifierPosition(List<Integer> positions, int wordIdx) { if (positions.isEmpty()) { return -1; } Iterator<Integer> it = positions.iterator(); int bestPos = it.next(); int bestDist = Math.abs(wordIdx - bestPos); while (it.hasNext()) { int pos = it.next(); int dist = Math.abs(wordIdx - pos); if (dist < bestDist) { bestDist = dist; bestPos = pos; } } return bestPos; } CreateCandidatesMapper(BaseConfig config); @Override WikiDocumentOutput map(ParsedWikiDocument doc); static List<Integer> identifierPositions(List<Word> sentence, String identifier); static int closestIdentifierPosition(List<Integer> positions, int wordIdx); static int calculateMax(Multiset<String> frequencies); static List<Sentence> findSentencesWithIdentifier(List<Sentence> sentences, String identifier);  }### Answer:
@Test public void closestIdentifierPosition() { List<Integer> positions = Arrays.asList(0, 10, 25); int actual = CreateCandidatesMapper.closestIdentifierPosition(positions, 4); assertEquals(0, actual); }
@Test public void closestIdentifierPosition_oneElement() { List<Integer> positions = Arrays.asList(10); int actual = CreateCandidatesMapper.closestIdentifierPosition(positions, 4); assertEquals(10, actual); }
@Test public void closestIdentifierPosition_lastElement() { List<Integer> positions = Arrays.asList(0, 10, 25); int actual = CreateCandidatesMapper.closestIdentifierPosition(positions, 20); assertEquals(25, actual); }