@Test public void read_FileReaderNull_JsonParserNull_NextTokenNotNull() throws Exception { File currentFile = new File("f1.json"); Reader fileReader = Mockito.mock(Reader.class); JsonParser jsonParser = Mockito.mock(JsonParser.class); List<File> importFiles = Lists.newArrayList(new File("f2.json")); String nextJudgment = "JUDGMENTDATA"; when(importFileUtils.getReader(Mockito.eq(currentFile))).thenReturn(fileReader); when(jsonFactory.createParser(Mockito.eq(fileReader))).thenReturn(jsonParser); when(jsonParser.nextToken()).thenReturn(JsonToken.START_ARRAY, JsonToken.START_OBJECT); when(jsonFormatter.formatCurrentTokenTree(Mockito.eq(jsonParser))).thenReturn(nextJudgment); resetDownloadReaderInternal(currentFile, null, null, importFiles); JsonJudgmentItem judgment = jsonImportDownloadReader.read(); verify(importFileUtils).getReader(Mockito.eq(currentFile)); verify(jsonFactory).createParser(Mockito.eq(fileReader)); verify(jsonFormatter).formatCurrentTokenTree(Mockito.eq(jsonParser)); assertDownloadReaderState(currentFile, fileReader, jsonParser, importFiles.get(0)); assertEquals(nextJudgment, judgment.getJson()); assertEquals(currentFile, 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);  }