### Question:
MainEntryPoint { private static void upgradeToCollectorAddressIfNeeded(File propFile) throws IOException { List<String> lines = readPropertiesFile(propFile); List<String> newLines = upgradeToCollectorAddressIfNeeded(lines); if (!newLines.equals(lines)) { writePropertiesFile(propFile, newLines); } } private  MainEntryPoint(); static void premain(Instrumentation instrumentation, Class<?>[] allPriorLoadedClasses,
            @Nullable File glowrootJarFile); static void runOfflineViewer(Directories directories,
            GlowrootAgentInitFactory glowrootAgentInitFactory); @EnsuresNonNull("startupLogger") static void initLogging(File confDir, @Nullable File sharedConfDir, File logDir,
            @Nullable Instrumentation instrumentation); @OnlyUsedByTests static void start(Map<String, String> properties); @OnlyUsedByTests static @Nullable GlowrootAgentInit getGlowrootAgentInit(); static final boolean PRINT_CLASS_LOADING; }### Answer:
@Test public void testUpgradeToCollectorAddress() { List<String> lines = ImmutableList.of("before=test", "collector.host=localhost", "collector.port=8181", "after=test"); List<String> newLines = MainEntryPoint.upgradeToCollectorAddressIfNeeded(lines); assertThat(newLines).containsExactly("before=test", "collector.address=localhost:8181", "after=test"); }
@Test public void testUpgradeToCollectorAddressBothEmpty() { List<String> lines = ImmutableList.of("before=test", "collector.host=", "collector.port=", "after=test"); List<String> newLines = MainEntryPoint.upgradeToCollectorAddressIfNeeded(lines); assertThat(newLines).containsExactly("before=test", "collector.address=", "after=test"); }
@Test public void testUpgradeToCollectorAddressBothMissing() { List<String> lines = ImmutableList.of("before=test", "after=test"); List<String> newLines = MainEntryPoint.upgradeToCollectorAddressIfNeeded(lines); assertThat(newLines).containsExactly("before=test", "after=test"); }
@Test public void testUpgradeToCollectorAddressOnlyHostEmpty() { List<String> lines = ImmutableList.of("before=test", "collector.host=", "collector.port=8181", "after=test"); List<String> newLines = MainEntryPoint.upgradeToCollectorAddressIfNeeded(lines); assertThat(newLines).containsExactly("before=test", "collector.address=", "after=test"); }
@Test public void testUpgradeToCollectorAddressOnlyPortEmpty() { List<String> lines = ImmutableList.of("before=test", "collector.host=localhost", "collector.port=", "after=test"); List<String> newLines = MainEntryPoint.upgradeToCollectorAddressIfNeeded(lines); assertThat(newLines).containsExactly("before=test", "collector.address=localhost:8181", "after=test"); }
@Test public void testUpgradeToCollectorAddressOnlyHostMissing() { List<String> lines = ImmutableList.of("before=test", "collector.port=8181", "after=test"); List<String> newLines = MainEntryPoint.upgradeToCollectorAddressIfNeeded(lines); assertThat(newLines).containsExactly("before=test", "after=test"); }
@Test public void testUpgradeToCollectorAddressOnlyPortMissing() { List<String> lines = ImmutableList.of("before=test", "collector.host=localhost", "after=test"); List<String> newLines = MainEntryPoint.upgradeToCollectorAddressIfNeeded(lines); assertThat(newLines).containsExactly("before=test", "collector.address=localhost:8181", "after=test"); }
@Test public void testUpgradeToCollectorAddressNotNeeded() { List<String> lines = ImmutableList.of("before=test", "collector.address=xyz:1234", "after=test"); List<String> newLines = MainEntryPoint.upgradeToCollectorAddressIfNeeded(lines); assertThat(newLines).isEqualTo(lines); }