ResponseMapper { @VisibleForTesting Pair<String, Integer> mapIdIteration(Cursor data) { int questionIdColumn = data.getColumnIndexOrThrow(ResponseColumns.QUESTION_ID); int iterationColumn = data.getColumnIndexOrThrow(ResponseColumns.ITERATION); String rawQuestionId = data.getString(questionIdColumn); int iteration = data.getInt(iterationColumn); String[] tokens = rawQuestionId.split("\\|", -1); if (tokens.length == 2) { rawQuestionId = tokens[0]; iteration = Integer.parseInt(tokens[1]); } iteration = Math.max(iteration, 0); return new Pair<>(rawQuestionId, iteration); } @Inject  ResponseMapper();   }
@Test public void mapIdIterationShouldParseCorrectlyCompoundQuestionIdIteration() { when(mockCursor.getString(0)).thenReturn("abc|1"); when(mockCursor.getInt(1)).thenReturn(0); Pair<String, Integer> mapped = mapper.mapIdIteration(mockCursor); assertEquals("abc", mapped.first); assertEquals(1, mapped.second.intValue()); }
@Test public void mapIdIterationShouldParseCorrectlyCorrectIterationField() { when(mockCursor.getString(0)).thenReturn("abc"); when(mockCursor.getInt(1)).thenReturn(0); Pair<String, Integer> mapped = mapper.mapIdIteration(mockCursor); assertEquals("abc", mapped.first); assertEquals(0, mapped.second.intValue()); }
@Test public void mapIdIterationShouldParseCorrectlyCorrectIterationInvalid() { when(mockCursor.getString(0)).thenReturn("abc"); when(mockCursor.getInt(1)).thenReturn(-1); Pair<String, Integer> mapped = mapper.mapIdIteration(mockCursor); assertEquals("abc", mapped.first); assertEquals(0, mapped.second.intValue()); }