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