Skip to content

Commit 0188c7c

Browse files
committed
Polishing.
Reformat code. Split tests into positives and negatives. [#656]
1 parent 26844d3 commit 0188c7c

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/main/java/io/r2dbc/postgresql/PostgresqlConnectionConfiguration.java

-1
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,6 @@ private static void appendSniHost(SSLParameters sslParameters, String hostString
12031203
sslParameters.setServerNames(serverNames);
12041204
}
12051205

1206-
12071206
private Supplier<SslContext> createSslProvider() {
12081207
SslContextBuilder sslContextBuilder = SslContextBuilder.forClient();
12091208
if (this.sslMode.verifyCertificate()) {
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package io.r2dbc.postgresql.client;
218

3-
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.params.ParameterizedTest;
20+
import org.junit.jupiter.params.provider.ValueSource;
421

522
import static org.assertj.core.api.Assertions.assertThat;
623

724
/**
825
* Unit tests for {@link SSLConfig}.
926
*/
1027
final class SSLConfigTests {
11-
@Test
12-
public void testValidSniHostname(){
13-
assertThat(SSLConfig.isValidSniHostname("example.com")).isEqualTo(true);
14-
assertThat(SSLConfig.isValidSniHostname("example://.com")).isEqualTo(false);
15-
assertThat(SSLConfig.isValidSniHostname("example.com.")).isEqualTo(false);
28+
29+
@ParameterizedTest
30+
@ValueSource(strings = {"example.com", "foo"})
31+
public void shouldAcceptValidSniHostname(String hostname) {
32+
assertThat(SSLConfig.isValidSniHostname(hostname)).isTrue();
33+
}
34+
35+
@ParameterizedTest
36+
@ValueSource(strings = {"example.com.", "example://.com"})
37+
public void shouldRejectValidSniHostname(String hostname) {
38+
assertThat(SSLConfig.isValidSniHostname(hostname)).isFalse();
1639
}
1740
}

0 commit comments

Comments
 (0)