@Test public void read_FileReaderNotNull_JsonParserNotNull_NextTokenNull_2Loops() throws Exception { File currentFile = new File("f1.json"); File currentFile2Loop = new File("f2.json"); Reader fileReader = Mockito.mock(Reader.class); JsonParser jsonParser = Mockito.mock(JsonParser.class); List<File> importFiles = Lists.newArrayList(currentFile2Loop); resetDownloadReaderInternal(currentFile, fileReader, jsonParser, importFiles); when(jsonParser.nextToken()).thenReturn(null); Reader fileReader2Loop = Mockito.mock(Reader.class); JsonParser jsonParser2Loop = Mockito.mock(JsonParser.class); String judgment2Loop = "JUDGMENT_DATA"; when(importFileUtils.getReader(Mockito.eq(currentFile2Loop))).thenReturn(fileReader2Loop); when(jsonFactory.createParser(Mockito.eq(fileReader2Loop))).thenReturn(jsonParser2Loop); when(jsonParser2Loop.nextToken()).thenReturn(JsonToken.START_OBJECT); when(jsonFormatter.formatCurrentTokenTree(jsonParser2Loop)).thenReturn(judgment2Loop); JsonJudgmentItem judgment = jsonImportDownloadReader.read(); verify(importFileUtils, Mockito.never()).getReader(Mockito.eq(currentFile)); verify(importFileUtils).getReader(Mockito.eq(currentFile2Loop)); verify(jsonFactory, Mockito.never()).createParser(Mockito.eq(fileReader)); verify(jsonFactory).createParser(Mockito.eq(fileReader2Loop)); verify(jsonParser).nextToken(); verify(jsonParser2Loop).nextToken(); verify(jsonFormatter).formatCurrentTokenTree(jsonParser2Loop); assertDownloadReaderState(currentFile2Loop, fileReader2Loop, jsonParser2Loop); assertEquals(judgment2Loop, judgment.getJson()); assertEquals(currentFile2Loop, judgment.getSourceMetadataFile()); }
@Override public JsonJudgmentItem read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { if (currentFile == null) { return null; } if (fileReader == null) { Preconditions.checkState(jsonParser == null || jsonParser.isClosed()); fileReader = importFileUtils.getReader(currentFile); } if (jsonParser == null || jsonParser.isClosed()) { jsonParser = jsonFactory.createParser(fileReader); } JsonToken jsonToken = jsonParser.nextToken(); if (jsonToken != null && JsonToken.START_ARRAY.equals(jsonToken)) { jsonToken = jsonParser.nextToken(); } if (jsonToken != null) { String judgment = jsonFormatter.formatCurrentTokenTree(jsonParser); if (judgment != null) { return new JsonJudgmentItem(StringUtils.trim(judgment), currentFile); } } closeJsonParser(); closeFileReader(); currentFile = importFiles.poll(); return read(); }
JsonImportDownloadReader implements ItemStreamReader<JsonJudgmentItem> { @Override public JsonJudgmentItem read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { if (currentFile == null) { return null; } if (fileReader == null) { Preconditions.checkState(jsonParser == null || jsonParser.isClosed()); fileReader = importFileUtils.getReader(currentFile); } if (jsonParser == null || jsonParser.isClosed()) { jsonParser = jsonFactory.createParser(fileReader); } JsonToken jsonToken = jsonParser.nextToken(); if (jsonToken != null && JsonToken.START_ARRAY.equals(jsonToken)) { jsonToken = jsonParser.nextToken(); } if (jsonToken != null) { String judgment = jsonFormatter.formatCurrentTokenTree(jsonParser); if (judgment != null) { return new JsonJudgmentItem(StringUtils.trim(judgment), currentFile); } } closeJsonParser(); closeFileReader(); currentFile = importFiles.poll(); return read(); } }
JsonImportDownloadReader implements ItemStreamReader<JsonJudgmentItem> { @Override public JsonJudgmentItem read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { if (currentFile == null) { return null; } if (fileReader == null) { Preconditions.checkState(jsonParser == null || jsonParser.isClosed()); fileReader = importFileUtils.getReader(currentFile); } if (jsonParser == null || jsonParser.isClosed()) { jsonParser = jsonFactory.createParser(fileReader); } JsonToken jsonToken = jsonParser.nextToken(); if (jsonToken != null && JsonToken.START_ARRAY.equals(jsonToken)) { jsonToken = jsonParser.nextToken(); } if (jsonToken != null) { String judgment = jsonFormatter.formatCurrentTokenTree(jsonParser); if (judgment != null) { return new JsonJudgmentItem(StringUtils.trim(judgment), currentFile); } } closeJsonParser(); closeFileReader(); currentFile = importFiles.poll(); return read(); }  }
JsonImportDownloadReader implements ItemStreamReader<JsonJudgmentItem> { @Override public JsonJudgmentItem read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { if (currentFile == null) { return null; } if (fileReader == null) { Preconditions.checkState(jsonParser == null || jsonParser.isClosed()); fileReader = importFileUtils.getReader(currentFile); } if (jsonParser == null || jsonParser.isClosed()) { jsonParser = jsonFactory.createParser(fileReader); } JsonToken jsonToken = jsonParser.nextToken(); if (jsonToken != null && JsonToken.START_ARRAY.equals(jsonToken)) { jsonToken = jsonParser.nextToken(); } if (jsonToken != null) { String judgment = jsonFormatter.formatCurrentTokenTree(jsonParser); if (judgment != null) { return new JsonJudgmentItem(StringUtils.trim(judgment), currentFile); } } closeJsonParser(); closeFileReader(); currentFile = importFiles.poll(); return read(); }  @Override JsonJudgmentItem read(); @Override void open(ExecutionContext executionContext); @Override void update(ExecutionContext executionContext); @Override void close(); void setImportDir(String importDir); @Autowired void setImportFileUtils(ImportFileUtils importFileUtils); @Autowired void setJsonFormatter(JsonFormatter jsonFormatter); @Autowired void setJsonFactory(JsonFactory jsonFactory); }
JsonImportDownloadReader implements ItemStreamReader<JsonJudgmentItem> { @Override public JsonJudgmentItem read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { if (currentFile == null) { return null; } if (fileReader == null) { Preconditions.checkState(jsonParser == null || jsonParser.isClosed()); fileReader = importFileUtils.getReader(currentFile); } if (jsonParser == null || jsonParser.isClosed()) { jsonParser = jsonFactory.createParser(fileReader); } JsonToken jsonToken = jsonParser.nextToken(); if (jsonToken != null && JsonToken.START_ARRAY.equals(jsonToken)) { jsonToken = jsonParser.nextToken(); } if (jsonToken != null) { String judgment = jsonFormatter.formatCurrentTokenTree(jsonParser); if (judgment != null) { return new JsonJudgmentItem(StringUtils.trim(judgment), currentFile); } } closeJsonParser(); closeFileReader(); currentFile = importFiles.poll(); return read(); }  @Override JsonJudgmentItem read(); @Override void open(ExecutionContext executionContext); @Override void update(ExecutionContext executionContext); @Override void close(); void setImportDir(String importDir); @Autowired void setImportFileUtils(ImportFileUtils importFileUtils); @Autowired void setJsonFormatter(JsonFormatter jsonFormatter); @Autowired void setJsonFactory(JsonFactory jsonFactory);  }