View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.enforcer.rules.checksum;
20  
21  import java.io.IOException;
22  import java.io.Reader;
23  import java.io.StringReader;
24  
25  import org.apache.commons.io.IOUtils;
26  import org.apache.maven.enforcer.rules.checksum.NormalizeLineSeparatorReader.LineSeparator;
27  import org.junit.jupiter.api.Test;
28  
29  import static org.junit.jupiter.api.Assertions.assertEquals;
30  
31  class TestNormalizeLineSeparatorReader {
32      private static final String UNIX_MULTILINE_STRING = "line1\nline2\n\n";
33  
34      private static final String WINDOWS_MULTILINE_STRING = "line1\r\nline2\r\n\r\n";
35  
36      @Test
37      void testUnixToWindows() throws IOException {
38          try (Reader reader =
39                  new NormalizeLineSeparatorReader(new StringReader(UNIX_MULTILINE_STRING), LineSeparator.WINDOWS)) {
40              assertEquals(WINDOWS_MULTILINE_STRING, IOUtils.toString(reader));
41          }
42      }
43  
44      @Test
45      void testUnixToUnix() throws IOException {
46          try (Reader reader =
47                  new NormalizeLineSeparatorReader(new StringReader(UNIX_MULTILINE_STRING), LineSeparator.UNIX)) {
48              assertEquals(UNIX_MULTILINE_STRING, IOUtils.toString(reader));
49          }
50      }
51  
52      @Test
53      void testWindowsToUnix() throws IOException {
54          try (Reader reader =
55                  new NormalizeLineSeparatorReader(new StringReader(WINDOWS_MULTILINE_STRING), LineSeparator.UNIX)) {
56              assertEquals(UNIX_MULTILINE_STRING, IOUtils.toString(reader));
57          }
58      }
59  
60      @Test
61      void testWindowsToWindows() throws IOException {
62          try (Reader reader =
63                  new NormalizeLineSeparatorReader(new StringReader(WINDOWS_MULTILINE_STRING), LineSeparator.WINDOWS)) {
64              assertEquals(WINDOWS_MULTILINE_STRING, IOUtils.toString(reader));
65          }
66      }
67  }