1616 */
1717package com .google .edwmigration .dumper .application .dumper ;
1818
19+ import static com .google .edwmigration .dumper .application .dumper .ConnectorArguments .OPT_HOST_DEFAULT ;
1920import static org .junit .Assert .assertEquals ;
21+ import static org .junit .Assert .assertNull ;
2022import static org .junit .Assert .assertThrows ;
2123import 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