@Test public void shouldNotParseInvalidJsonFile() { List<Feature> features = FeatureParser.parse(FileUtil.findJsonFile("json-output/invalid_json.json")); assertNull(features); }
public static List<Feature> parse(String json) { List<Feature> features = null; try (InputStreamReader is = new InputStreamReader(new FileInputStream(json),"UTF-8")) { features = new ObjectMapper().readValue(is, new TypeReference<List<Feature>>() { }); Iterator<Feature> it = features.iterator(); while (it.hasNext()) { Feature feature = it.next(); if (!feature.isCucumberFeature()) { log.warning("json:" + json + " is NOT a Cucumber feature result file and will be ignored"); it.remove(); }else{ feature.initScenarios(); feature.processSteps(); } } } catch (FileNotFoundException e) { log.log(Level.WARNING, "Could not find json file:" + json); } catch (JsonMappingException e) { log.log(Level.WARNING, "Could not map json file:" + json); } catch (JsonParseException e) { log.log(Level.WARNING, "Could not parse json file:" + json); } catch (IOException e) { log.log(Level.WARNING, "Could not read json file:" + json); } return features; }
FeatureParser { public static List<Feature> parse(String json) { List<Feature> features = null; try (InputStreamReader is = new InputStreamReader(new FileInputStream(json),"UTF-8")) { features = new ObjectMapper().readValue(is, new TypeReference<List<Feature>>() { }); Iterator<Feature> it = features.iterator(); while (it.hasNext()) { Feature feature = it.next(); if (!feature.isCucumberFeature()) { log.warning("json:" + json + " is NOT a Cucumber feature result file and will be ignored"); it.remove(); }else{ feature.initScenarios(); feature.processSteps(); } } } catch (FileNotFoundException e) { log.log(Level.WARNING, "Could not find json file:" + json); } catch (JsonMappingException e) { log.log(Level.WARNING, "Could not map json file:" + json); } catch (JsonParseException e) { log.log(Level.WARNING, "Could not parse json file:" + json); } catch (IOException e) { log.log(Level.WARNING, "Could not read json file:" + json); } return features; } }
FeatureParser { public static List<Feature> parse(String json) { List<Feature> features = null; try (InputStreamReader is = new InputStreamReader(new FileInputStream(json),"UTF-8")) { features = new ObjectMapper().readValue(is, new TypeReference<List<Feature>>() { }); Iterator<Feature> it = features.iterator(); while (it.hasNext()) { Feature feature = it.next(); if (!feature.isCucumberFeature()) { log.warning("json:" + json + " is NOT a Cucumber feature result file and will be ignored"); it.remove(); }else{ feature.initScenarios(); feature.processSteps(); } } } catch (FileNotFoundException e) { log.log(Level.WARNING, "Could not find json file:" + json); } catch (JsonMappingException e) { log.log(Level.WARNING, "Could not map json file:" + json); } catch (JsonParseException e) { log.log(Level.WARNING, "Could not parse json file:" + json); } catch (IOException e) { log.log(Level.WARNING, "Could not read json file:" + json); } return features; }  }
FeatureParser { public static List<Feature> parse(String json) { List<Feature> features = null; try (InputStreamReader is = new InputStreamReader(new FileInputStream(json),"UTF-8")) { features = new ObjectMapper().readValue(is, new TypeReference<List<Feature>>() { }); Iterator<Feature> it = features.iterator(); while (it.hasNext()) { Feature feature = it.next(); if (!feature.isCucumberFeature()) { log.warning("json:" + json + " is NOT a Cucumber feature result file and will be ignored"); it.remove(); }else{ feature.initScenarios(); feature.processSteps(); } } } catch (FileNotFoundException e) { log.log(Level.WARNING, "Could not find json file:" + json); } catch (JsonMappingException e) { log.log(Level.WARNING, "Could not map json file:" + json); } catch (JsonParseException e) { log.log(Level.WARNING, "Could not parse json file:" + json); } catch (IOException e) { log.log(Level.WARNING, "Could not read json file:" + json); } return features; }  static List<Feature> parse(String json); static List<Feature> parse(List<String> paths); static List<Feature> parse(String... paths); static List<Feature> findAndParse(String basePath); }
FeatureParser { public static List<Feature> parse(String json) { List<Feature> features = null; try (InputStreamReader is = new InputStreamReader(new FileInputStream(json),"UTF-8")) { features = new ObjectMapper().readValue(is, new TypeReference<List<Feature>>() { }); Iterator<Feature> it = features.iterator(); while (it.hasNext()) { Feature feature = it.next(); if (!feature.isCucumberFeature()) { log.warning("json:" + json + " is NOT a Cucumber feature result file and will be ignored"); it.remove(); }else{ feature.initScenarios(); feature.processSteps(); } } } catch (FileNotFoundException e) { log.log(Level.WARNING, "Could not find json file:" + json); } catch (JsonMappingException e) { log.log(Level.WARNING, "Could not map json file:" + json); } catch (JsonParseException e) { log.log(Level.WARNING, "Could not parse json file:" + json); } catch (IOException e) { log.log(Level.WARNING, "Could not read json file:" + json); } return features; }  static List<Feature> parse(String json); static List<Feature> parse(List<String> paths); static List<Feature> parse(String... paths); static List<Feature> findAndParse(String basePath);  }