1717package com .google .cloud .bigquery .jdbc ;
1818
1919import static com .google .common .truth .Truth .assertThat ;
20+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
2021import static org .junit .jupiter .api .Assertions .assertFalse ;
2122import static org .junit .jupiter .api .Assertions .assertNull ;
22- import static org .junit .jupiter .api .Assertions .assertThrows ;
2323
24- import com .google .cloud .bigquery .exception .BigQueryJdbcRuntimeException ;
2524import java .util .Collections ;
2625import java .util .Map ;
2726import java .util .Properties ;
2827import org .junit .jupiter .api .Test ;
2928
30- public class BigQueryJdbcUrlUtilityTest {
29+ public class BigQueryJdbcUrlUtilityTest extends BigQueryJdbcLoggingBaseTest {
3130
3231 @ Test
3332 public void testParsePropertyWithNoDefault () {
@@ -41,27 +40,25 @@ public void testParsePropertyWithNoDefault() {
4140 }
4241
4342 @ Test
44- public void testParseUrlWithUnknownProperty_throwsException () {
43+ public void testParseUrlWithUnknownProperty_no_exception () {
4544 String url =
4645 "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
4746 + "ProjectId=MyBigQueryProject;"
4847 + "UnknownProperty=SomeValue" ;
4948
50- assertThrows (
51- BigQueryJdbcRuntimeException .class ,
52- () -> BigQueryJdbcUrlUtility .parseUriProperty (url , "ProjectId" ));
49+ BigQueryJdbcUrlUtility .parseUriProperty (url , "ProjectId" );
50+ assertThat (assertLogContains ("Wrong value or unknown setting" )).isTrue ();
5351 }
5452
5553 @ Test
56- public void testParseUrlWithTypo_throwsException () {
54+ public void testParseUrlWithTypo_no_exception () {
5755 String url =
5856 "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
5957 + "ProjectId=MyBigQueryProject;"
6058 + "ProjeectId=TypoValue" ;
6159
62- assertThrows (
63- BigQueryJdbcRuntimeException .class ,
64- () -> BigQueryJdbcUrlUtility .parseUriProperty (url , "ProjectId" ));
60+ assertDoesNotThrow (() -> BigQueryJdbcUrlUtility .parseUriProperty (url , "ProjectId" ));
61+ assertThat (assertLogContains ("Wrong value or unknown setting" )).isTrue ();
6562 }
6663
6764 @ Test
@@ -72,7 +69,7 @@ public void testParsePropertyWithDefault() {
7269 + "OAuthAccessToken=RedactedToken" ;
7370
7471 String result = BigQueryJdbcUrlUtility .parseUriProperty (url , "OAuthType" );
75- assertThat (result ).isEqualTo ( null );
72+ assertThat (result ).isNull ( );
7673 }
7774
7875 @ Test
@@ -143,14 +140,12 @@ public void testParseUrl_longUnknownProperty_sanitized() {
143140 String longKey = String .join ("" , Collections .nCopies (50 , "a" ));
144141 String url = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + longKey + "=value" ;
145142
146- BigQueryJdbcRuntimeException e =
147- assertThrows (
148- BigQueryJdbcRuntimeException .class , () -> BigQueryJdbcUrlUtility .parseUrl (url ));
149-
150- assertThat (e .getMessage ()).contains ("Wrong value or unknown setting: " );
151- assertThat (e .getMessage ()).contains ("..." );
152- assertThat (e .getMessage ()).doesNotContain (longKey );
153- assertThat (e .getMessage ().length ()).isLessThan (100 );
143+ assertDoesNotThrow (() -> BigQueryJdbcUrlUtility .parseUrl (url ));
144+ String message = capturedLogs .get (0 ).getMessage ();
145+ assertThat (message ).contains ("Wrong value or unknown setting: " );
146+ assertThat (message ).contains ("..." );
147+ assertThat (message ).doesNotContain (longKey );
148+ assertThat (message .length ()).isLessThan (100 );
154149 }
155150
156151 @ Test
0 commit comments