Skip to content

Commit a597539

Browse files
authored
Improve tests of getHost, getHostOrDefault in ConnectorArguments (#516)
1 parent 975d99b commit a597539

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/ConnectorArgumentsTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
*/
1717
package com.google.edwmigration.dumper.application.dumper;
1818

19+
import static com.google.edwmigration.dumper.application.dumper.ConnectorArguments.OPT_HOST_DEFAULT;
1920
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNull;
2022
import static org.junit.Assert.assertThrows;
2123
import static org.junit.Assert.assertTrue;
2224

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

74+
@Test
75+
public void getHost_notProvidedInFlag_useArgument() {
76+
ConnectorArguments arguments = arguments("--connector", "oracle");
77+
78+
assertEquals("default-host-789", arguments.getHost("default-host-789"));
79+
}
80+
81+
@Test
82+
public void getHost_providedInFlag_useFlagAndIgnoreArgument() {
83+
ConnectorArguments arguments = arguments("--connector", "oracle", "--host", "example-host-123");
84+
85+
assertEquals("example-host-123", arguments.getHost("default-host-789"));
86+
}
87+
88+
@Test
89+
public void getHostOrDefault_notProvidedInFlag_useDefault() {
90+
ConnectorArguments arguments = arguments("--connector", "oracle");
91+
92+
assertEquals(OPT_HOST_DEFAULT, arguments.getHostOrDefault());
93+
}
94+
95+
@Test
96+
public void getHostOrDefault_providedInFlag_useFlag() {
97+
ConnectorArguments arguments = arguments("--connector", "oracle", "--host", "example-host-123");
98+
99+
assertEquals("example-host-123", arguments.getHostOrDefault());
100+
}
101+
102+
@Test
103+
public void getHost_notProvidedInFlag_returnNull() {
104+
ConnectorArguments arguments = arguments("--connector", "oracle");
105+
106+
assertNull(arguments.getHost());
107+
}
108+
109+
@Test
110+
public void getHost_providedInFlag_useFlag() {
111+
ConnectorArguments arguments = arguments("--connector", "oracle", "--host", "example-host-123");
112+
113+
assertEquals("example-host-123", arguments.getHost());
114+
}
115+
72116
@Test
73117
public void getUserOrFail_noUserFlag_throwsException() throws IOException {
74118
ConnectorArguments arguments = new ConnectorArguments("--connector", "abcABC123");
@@ -91,4 +135,13 @@ public void getUserOrFail_success() throws IOException {
91135

92136
assertEquals(expectedName, actualName);
93137
}
138+
139+
// helper method to suppress IOException
140+
private static ConnectorArguments arguments(String... terms) {
141+
try {
142+
return new ConnectorArguments(terms);
143+
} catch (IOException e) {
144+
throw new RuntimeException(e);
145+
}
146+
}
94147
}

0 commit comments

Comments
 (0)