View Javadoc
1   package org.apache.maven.doxia.siterenderer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.ByteArrayInputStream;
23  import java.io.IOException;
24  import java.io.InputStream;
25  
26  import org.apache.maven.doxia.sink.impl.AbstractSink;
27  import org.codehaus.plexus.util.IOUtil;
28  import org.junit.Test;
29  
30  import static org.junit.Assert.assertEquals;
31  
32  public class SkinResourceLoaderTest
33  {
34      private SkinResourceLoader skinResourceLoader = new SkinResourceLoader();
35  
36      @Test
37      public void testNormalizeNewline() throws Exception
38      {
39          String EOL = AbstractSink.EOL;
40          String EOL_MACOS9 = "\r";
41          String EOL_UNIX = "\n";
42          String EOL_WIN = "\r\n";
43          
44          assertEquals( "Hello " + EOL + " world", normalizeNewline( "Hello " + EOL_MACOS9 + " world" ) );
45          assertEquals( "Hello " + EOL + " world", normalizeNewline( "Hello " + EOL_UNIX + " world" ) );
46          assertEquals( "Hello " + EOL + " world", normalizeNewline( "Hello " + EOL_WIN + " world" ) );
47  
48          assertEquals( "Hello world" + EOL, normalizeNewline( "Hello world" + EOL_MACOS9 ) );
49          assertEquals( "Hello world" + EOL, normalizeNewline( "Hello world" + EOL_UNIX ) );
50          assertEquals( "Hello world" + EOL, normalizeNewline( "Hello world" + EOL_WIN ) );
51  
52          assertEquals( EOL + "Hello world", normalizeNewline( EOL_MACOS9 + "Hello world" ) );
53          assertEquals( EOL + "Hello world", normalizeNewline( EOL_UNIX + "Hello world" ) );
54          assertEquals( EOL + "Hello world", normalizeNewline( EOL_WIN + "Hello world" ) );
55      }
56      
57      private String normalizeNewline( String  text ) throws IOException
58      {
59          InputStream in = new ByteArrayInputStream( text.getBytes() ); 
60          InputStream out = skinResourceLoader.normalizeNewline( in );
61          return IOUtil.toString( out );
62      }
63  }