View Javadoc
1   /*
2    * Copyright 2019-2021 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  
17  package nl.altindag.ssl.util;
18  
19  import org.junit.jupiter.api.Test;
20  import java.net.URI;
21  
22  import static org.assertj.core.api.Assertions.assertThatThrownBy;
23  
24  /**
25   * @author Hakan Altindag
26   */
27  class UriUtilsShould {
28  
29      @Test
30      void throwExceptionWhenNullIsProvidedWhenValidateIsCalled() {
31          assertThatThrownBy(() -> UriUtils.validate(null))
32                  .isInstanceOf(IllegalArgumentException.class)
33                  .hasMessage("Host should be present");
34      }
35  
36      @Test
37      void throwExceptionWhenHostIsProvidedWithoutAValidPortIsProvidedWhenValidateIsCalled() {
38          URI host = URI.create("https://localhost/");
39          assertThatThrownBy(() -> UriUtils.validate(host))
40                  .isInstanceOf(IllegalArgumentException.class)
41                  .hasMessage("Port should be defined for the given input: [https://localhost/]");
42      }
43  
44      @Test
45      void throwExceptionWhenHostIsProvidedWithoutAValidHostnameIsProvidedWhenValidateIsCalled() {
46          URI host = URI.create("https:/");
47          assertThatThrownBy(() -> UriUtils.validate(host))
48                  .isInstanceOf(IllegalArgumentException.class)
49                  .hasMessage("Hostname should be defined for the given input: [https:/]");
50      }
51  
52  }