### Question:
ProxyConfigurationMigrator implements PreConfigurationUpdateModule { protected ProxyConfigurations convertPreferences(Map<String, String> preferences) { ProxyConfigurations proxyConfigs = new ProxyConfigurations(); List<String> exclusions = new ArrayList<>(); if (preferences.get("ProxyExclusionPatterns") != null) { exclusions = Arrays.asList(preferences.get("ProxyExclusionPatterns").trim().split(" +|, +|,")); } if (Boolean.parseBoolean(preferences.get("SystemProxiesEnabled"))) { proxyConfigs.setSelectedConfigurationType(ConfigurationType.SYSTEM); proxyConfigs.getSystemProxyConfiguration().getExclusionPatterns().addAll(exclusions); } else if (preferences.get("ProxyConfigUrl") != null) { proxyConfigs.setSelectedConfigurationType(ConfigurationType.URL); proxyConfigs.getUrlProxyConfiguration().setProxyUrl(preferences.get("ProxyConfigUrl")); } else if (preferences.get("ProxyPort") != null) { proxyConfigs.setSelectedConfigurationType(ConfigurationType.MANUAL); proxyConfigs.getManualProxyConfiguration() .setHost(preferences.get("ProxyHost") != null ? preferences.get("ProxyHost") : ""); proxyConfigs.getManualProxyConfiguration().setPort(Integer.parseInt(preferences.get("ProxyPort"))); proxyConfigs.getManualProxyConfiguration().getExclusionPatterns().addAll(exclusions); } else { proxyConfigs.setSelectedConfigurationType(ConfigurationType.NONE); } return proxyConfigs; }  @Override void updateConfigs(PreferencesRegistry prefsRegistry);  }### Answer:
@Test public void testConvertPreferencesNoProxy() { ProxyConfigurations expectedConfigs = new ProxyConfigurations(); expectedConfigs.setSelectedConfigurationType(ConfigurationType.NONE); Map<String, String> preferenceValues = new HashMap<String, String>(); preferenceValues.put("SystemProxiesEnabled", "false"); ProxyConfigurations actualConfigs = new ProxyConfigurationMigrator().convertPreferences(preferenceValues); assertTrue(configsMatch(expectedConfigs, actualConfigs)); }
@Test public void testConvertPreferencesSystemProxy() { ProxyConfigurations expectedConfigs = new ProxyConfigurations(); expectedConfigs.setSelectedConfigurationType(ConfigurationType.SYSTEM); expectedConfigs.getSystemProxyConfiguration().getExclusionPatterns() .addAll(new HashSet<String>(Arrays.asList("example1", "example2", "example3", "example4"))); Map<String, String> preferenceValues = new HashMap<String, String>(); preferenceValues.put("SystemProxiesEnabled", "true"); preferenceValues.put("ProxyExclusionPatterns", " example1, example2,example3 example4 "); ProxyConfigurations actualConfigs = new ProxyConfigurationMigrator().convertPreferences(preferenceValues); assertTrue(configsMatch(expectedConfigs, actualConfigs)); }
@Test public void testConvertPreferencesUrlProxy() { ProxyConfigurations expectedConfigs = new ProxyConfigurations(); expectedConfigs.setSelectedConfigurationType(ConfigurationType.URL); expectedConfigs.getUrlProxyConfiguration().setProxyUrl("example-url"); Map<String, String> preferenceValues = new HashMap<String, String>(); preferenceValues.put("SystemProxiesEnabled", "false"); preferenceValues.put("ProxyConfigUrl", "example-url"); ProxyConfigurations actualConfigs = new ProxyConfigurationMigrator().convertPreferences(preferenceValues); assertTrue(configsMatch(expectedConfigs, actualConfigs)); }
@Test public void testConvertPreferencesManualProxy() { ProxyConfigurations expectedConfigs = new ProxyConfigurations(); expectedConfigs.setSelectedConfigurationType(ConfigurationType.MANUAL); expectedConfigs.getManualProxyConfiguration().setHost("example-host"); expectedConfigs.getManualProxyConfiguration().setPort(80); expectedConfigs.getManualProxyConfiguration().getExclusionPatterns() .addAll(new HashSet<String>(Arrays.asList("example1", "example2", "example3"))); Map<String, String> preferenceValues = new HashMap<String, String>(); preferenceValues.put("SystemProxiesEnabled", "false"); preferenceValues.put("ProxyHost", "example-host"); preferenceValues.put("ProxyPort", "80"); preferenceValues.put("ProxyExclusionPatterns", "example1 example2 example3"); ProxyConfigurations actualConfigs = new ProxyConfigurationMigrator().convertPreferences(preferenceValues); assertTrue(configsMatch(expectedConfigs, actualConfigs)); }