Skip to content

Commit

Permalink
Improve tests of getHost, getHostOrDefault in ConnectorArguments (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
misolt authored Aug 9, 2024
1 parent 975d99b commit a597539
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package com.google.edwmigration.dumper.application.dumper;

import static com.google.edwmigration.dumper.application.dumper.ConnectorArguments.OPT_HOST_DEFAULT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -69,6 +71,48 @@ public void getDatabases_trimDatabaseNamesFilteringOutBlankStrings() throws IOEx
assertEquals(ImmutableList.of("db1", "db2"), databaseNames);
}

@Test
public void getHost_notProvidedInFlag_useArgument() {
ConnectorArguments arguments = arguments("--connector", "oracle");

assertEquals("default-host-789", arguments.getHost("default-host-789"));
}

@Test
public void getHost_providedInFlag_useFlagAndIgnoreArgument() {
ConnectorArguments arguments = arguments("--connector", "oracle", "--host", "example-host-123");

assertEquals("example-host-123", arguments.getHost("default-host-789"));
}

@Test
public void getHostOrDefault_notProvidedInFlag_useDefault() {
ConnectorArguments arguments = arguments("--connector", "oracle");

assertEquals(OPT_HOST_DEFAULT, arguments.getHostOrDefault());
}

@Test
public void getHostOrDefault_providedInFlag_useFlag() {
ConnectorArguments arguments = arguments("--connector", "oracle", "--host", "example-host-123");

assertEquals("example-host-123", arguments.getHostOrDefault());
}

@Test
public void getHost_notProvidedInFlag_returnNull() {
ConnectorArguments arguments = arguments("--connector", "oracle");

assertNull(arguments.getHost());
}

@Test
public void getHost_providedInFlag_useFlag() {
ConnectorArguments arguments = arguments("--connector", "oracle", "--host", "example-host-123");

assertEquals("example-host-123", arguments.getHost());
}

@Test
public void getUserOrFail_noUserFlag_throwsException() throws IOException {
ConnectorArguments arguments = new ConnectorArguments("--connector", "abcABC123");
Expand All @@ -91,4 +135,13 @@ public void getUserOrFail_success() throws IOException {

assertEquals(expectedName, actualName);
}

// helper method to suppress IOException
private static ConnectorArguments arguments(String... terms) {
try {
return new ConnectorArguments(terms);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit a597539

Please sign in to comment.