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    *      http://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.geometry.io.core.input;
18  
19  import java.io.ByteArrayInputStream;
20  import java.nio.charset.StandardCharsets;
21  
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  
25  class StreamGeometryInputTest {
26  
27      private final ByteArrayInputStream byteStream = new ByteArrayInputStream(new byte[0]);
28  
29      @Test
30      void testCtor_stream() {
31          // act
32          final StreamGeometryInput in = new StreamGeometryInput(byteStream);
33  
34          // assert
35          Assertions.assertNull(in.getFileName());
36          Assertions.assertNull(in.getCharset());
37          Assertions.assertEquals(byteStream, in.getInputStream());
38      }
39  
40      @Test
41      void testCtor_streamAndFileName() {
42          // act
43          final StreamGeometryInput in = new StreamGeometryInput(byteStream, "test.txt");
44  
45          // assert
46          Assertions.assertEquals("test.txt", in.getFileName());
47          Assertions.assertNull(in.getCharset());
48          Assertions.assertEquals(byteStream, in.getInputStream());
49      }
50  
51      @Test
52      void testCtor_allArgs() {
53          // act
54          final StreamGeometryInput in = new StreamGeometryInput(byteStream, "test.txt", StandardCharsets.UTF_16);
55  
56          // assert
57          Assertions.assertEquals("test.txt", in.getFileName());
58          Assertions.assertEquals(StandardCharsets.UTF_16, in.getCharset());
59          Assertions.assertEquals(byteStream, in.getInputStream());
60      }
61  
62      @Test
63      void testToString() {
64          // arrange
65          final StreamGeometryInput in = new StreamGeometryInput(byteStream, "abc.txt");
66  
67          // act
68          final String result = in.toString();
69  
70          // assert
71          Assertions.assertEquals("StreamGeometryInput[fileName= abc.txt]", result);
72      }
73  }