### Question:
PluginListParser { public List<Plugin> parsePluginYamlFile(File pluginYamlFile) { List<Plugin> pluginsFromYaml = new ArrayList<>(); if (fileExists(pluginYamlFile)) { try (InputStream inputStream = new FileInputStream(pluginYamlFile)) { Plugins plugins = MAPPER.readValue(inputStream, Plugins.class); for (PluginInfo pluginInfo : plugins.getPlugins()) { String name = pluginInfo.getArtifactId(); if (StringUtils.isEmpty(name)) { throw new PluginInputException("ArtifactId is required"); } String groupId = pluginInfo.getGroupId(); Source pluginSource = pluginInfo.getSource(); Plugin plugin; if (pluginSource == null && StringUtils.isNotEmpty(groupId)) { throw new PluginInputException("Version must be input for " + name); } else if (pluginSource == null) { plugin = new Plugin(name, "latest", null, null); } else { String version = pluginSource.getVersion(); if (StringUtils.isNotEmpty(groupId) && version == null) { throw new PluginInputException("Version must be input for " + name); } if (version == null) { version = "latest"; } String url = pluginSource.getUrl(); if (!isURL(url)) { url = null; } plugin = new Plugin(name, version, url, groupId); } pluginsFromYaml.add(plugin); } } catch (IOException e) { System.out.println("Unable to open " + pluginsFromYaml); e.printStackTrace(); } } return pluginsFromYaml; } PluginListParser(boolean verbose); List<Plugin> parsePluginsFromCliOption(String[] plugins); List<Plugin> parsePluginTxtFile(File pluginTxtFile); List<Plugin> parsePluginYamlFile(File pluginYamlFile); boolean fileExists(File pluginFile); static boolean isURL(String url);  }### Answer:
@Test public void parsePluginYamlFileTest() throws URISyntaxException { List<Plugin> noFilePluginList = pluginList.parsePluginYamlFile(null); assertThat(noFilePluginList).isEmpty(); File pluginYmlFile = new File(this.getClass().getResource("PluginListParserTest/plugins.yaml").toURI()); List<Plugin> pluginsFromYamlFile = pluginList.parsePluginYamlFile(pluginYmlFile); List<String> pluginInfo = new ArrayList<>(); for (Plugin p : pluginsFromYamlFile) { System.out.println(p.toString()); pluginInfo.add(p.toString()); } assertThat(pluginInfo).containsExactly(expectedPluginInfo); }
@Test public void badFormatYamlNoArtifactIdTest() throws URISyntaxException { File pluginYmlFile = new File(this.getClass().getResource("PluginListParserTest/badformat1.yaml").toURI()); assertThatThrownBy(() -> pluginList.parsePluginYamlFile(pluginYmlFile)) .isInstanceOf(PluginInputException.class); }
@Test public void badFormatYamlGroupIdNoVersion() throws URISyntaxException { File pluginYmlFile = new File(this.getClass().getResource("PluginListParserTest/badformat2.yaml").toURI()); assertThatThrownBy(() -> pluginList.parsePluginYamlFile(pluginYmlFile)) .isInstanceOf(PluginInputException.class); }
@Test public void badFormatYamlGroupIdNoVersion2() throws URISyntaxException { File pluginYmlFile = new File(this.getClass().getResource("PluginListParserTest/badformat3.yaml").toURI()); assertThatThrownBy(() -> pluginList.parsePluginYamlFile(pluginYmlFile)) .isInstanceOf(PluginInputException.class); }