@Test public void convert() { List<Plugin> originalPlugins = singletonList(plugin("mailer", "1.31")); List<Plugin> latestVersionsOfPlugins = pm.getLatestVersionsOfPlugins(originalPlugins); String converted = new StdOutPluginOutputConverter(originalPlugins).convert(latestVersionsOfPlugins); assertThat(converted.trim().replaceAll("\r\n", "\n")) .isEqualTo(format("Available updates:%n" + "mailer (1.31) has an available update: 1.32%n").trim().replaceAll("\r\n", "\n")); }
@Override public String convert(List<Plugin> plugins) { Map<String, Plugin> pluginsAsMap = plugins.stream() .collect(Collectors.toMap(Plugin::getName, plugin -> plugin)); StringBuilder builder = new StringBuilder("Available updates:\n"); for (Plugin plugin : originalPlugins) { VersionNumber originalVersion = plugin.getVersion(); VersionNumber newVersion = pluginsAsMap.get(plugin.getName()).getVersion(); if (originalVersion.isOlderThan(newVersion)) { builder.append(String.format("%s (%s) has an available update: %s%n", plugin.getName(), plugin.getVersion(), newVersion)); } } String result = builder.toString(); if (!result.contains("has an")) { return "No available updates\n"; } return result; }
StdOutPluginOutputConverter implements PluginOutputConverter { @Override public String convert(List<Plugin> plugins) { Map<String, Plugin> pluginsAsMap = plugins.stream() .collect(Collectors.toMap(Plugin::getName, plugin -> plugin)); StringBuilder builder = new StringBuilder("Available updates:\n"); for (Plugin plugin : originalPlugins) { VersionNumber originalVersion = plugin.getVersion(); VersionNumber newVersion = pluginsAsMap.get(plugin.getName()).getVersion(); if (originalVersion.isOlderThan(newVersion)) { builder.append(String.format("%s (%s) has an available update: %s%n", plugin.getName(), plugin.getVersion(), newVersion)); } } String result = builder.toString(); if (!result.contains("has an")) { return "No available updates\n"; } return result; } }
StdOutPluginOutputConverter implements PluginOutputConverter { @Override public String convert(List<Plugin> plugins) { Map<String, Plugin> pluginsAsMap = plugins.stream() .collect(Collectors.toMap(Plugin::getName, plugin -> plugin)); StringBuilder builder = new StringBuilder("Available updates:\n"); for (Plugin plugin : originalPlugins) { VersionNumber originalVersion = plugin.getVersion(); VersionNumber newVersion = pluginsAsMap.get(plugin.getName()).getVersion(); if (originalVersion.isOlderThan(newVersion)) { builder.append(String.format("%s (%s) has an available update: %s%n", plugin.getName(), plugin.getVersion(), newVersion)); } } String result = builder.toString(); if (!result.contains("has an")) { return "No available updates\n"; } return result; } StdOutPluginOutputConverter(List<Plugin> originalPlugins); }
StdOutPluginOutputConverter implements PluginOutputConverter { @Override public String convert(List<Plugin> plugins) { Map<String, Plugin> pluginsAsMap = plugins.stream() .collect(Collectors.toMap(Plugin::getName, plugin -> plugin)); StringBuilder builder = new StringBuilder("Available updates:\n"); for (Plugin plugin : originalPlugins) { VersionNumber originalVersion = plugin.getVersion(); VersionNumber newVersion = pluginsAsMap.get(plugin.getName()).getVersion(); if (originalVersion.isOlderThan(newVersion)) { builder.append(String.format("%s (%s) has an available update: %s%n", plugin.getName(), plugin.getVersion(), newVersion)); } } String result = builder.toString(); if (!result.contains("has an")) { return "No available updates\n"; } return result; } StdOutPluginOutputConverter(List<Plugin> originalPlugins); @Override String convert(List<Plugin> plugins); }
StdOutPluginOutputConverter implements PluginOutputConverter { @Override public String convert(List<Plugin> plugins) { Map<String, Plugin> pluginsAsMap = plugins.stream() .collect(Collectors.toMap(Plugin::getName, plugin -> plugin)); StringBuilder builder = new StringBuilder("Available updates:\n"); for (Plugin plugin : originalPlugins) { VersionNumber originalVersion = plugin.getVersion(); VersionNumber newVersion = pluginsAsMap.get(plugin.getName()).getVersion(); if (originalVersion.isOlderThan(newVersion)) { builder.append(String.format("%s (%s) has an available update: %s%n", plugin.getName(), plugin.getVersion(), newVersion)); } } String result = builder.toString(); if (!result.contains("has an")) { return "No available updates\n"; } return result; } StdOutPluginOutputConverter(List<Plugin> originalPlugins); @Override String convert(List<Plugin> plugins);  }