View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.io.build;
18  
19  import static org.junit.jupiter.api.Assertions.assertNotEquals;
20  
21  import java.io.InputStream;
22  import java.net.URI;
23  import java.nio.file.Paths;
24  
25  import org.apache.commons.io.build.AbstractOrigin.URIOrigin;
26  import org.junit.jupiter.api.Test;
27  import org.junit.jupiter.params.ParameterizedTest;
28  import org.junit.jupiter.params.provider.ValueSource;
29  
30  /**
31   * Tests {@link URIOrigin}.
32   *
33   * A URIOrigin can convert into all other aspects.
34   *
35   * @see URI
36   */
37  class URIOriginTest extends AbstractOriginTest<URI, URIOrigin> {
38  
39      @Override
40      protected URIOrigin newOriginRo() {
41          return new URIOrigin(Paths.get(FILE_NAME_RO).toUri());
42      }
43  
44      @Override
45      protected URIOrigin newOriginRw() {
46          return new URIOrigin(Paths.get(FILE_NAME_RW).toUri());
47      }
48  
49      @ParameterizedTest
50      @ValueSource(strings = {
51              "http://example.com",
52              "https://example.com"
53      })
54      void testGetInputStream(final String uri) throws Exception {
55          final AbstractOrigin.URIOrigin origin = new AbstractOrigin.URIOrigin(new URI(uri));
56          try (InputStream in = origin.getInputStream()) {
57              assertNotEquals(-1, in.read());
58          }
59      }
60  
61      @Test
62      void testGetInputStreamFileURI() throws Exception {
63          final AbstractOrigin.URIOrigin origin = getOriginRo().asThis();
64          try (InputStream in = origin.getInputStream()) {
65              assertNotEquals(-1, in.read());
66          }
67      }
68  }