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 junit.framework.TestCase;
27  
28  import org.apache.maven.doxia.sink.impl.AbstractSink;
29  import org.codehaus.plexus.util.IOUtil;
30  
31  public class SkinResourceLoaderTest
32      extends TestCase
33  {
34      private SkinResourceLoader skinResourceLoader = new SkinResourceLoader();
35  
36      public void testNormalizeNewline() throws Exception
37      {
38          String EOL = AbstractSink.EOL;
39          String EOL_MACOS9 = "\r";
40          String EOL_UNIX = "\n";
41          String EOL_WIN = "\r\n";
42          
43          assertEquals( "Hello " + EOL + " world", normalizeNewline( "Hello " + EOL_MACOS9 + " world" ) );
44          assertEquals( "Hello " + EOL + " world", normalizeNewline( "Hello " + EOL_UNIX + " world" ) );
45          assertEquals( "Hello " + EOL + " world", normalizeNewline( "Hello " + EOL_WIN + " world" ) );
46  
47          assertEquals( "Hello world" + EOL, normalizeNewline( "Hello world" + EOL_MACOS9 ) );
48          assertEquals( "Hello world" + EOL, normalizeNewline( "Hello world" + EOL_UNIX ) );
49          assertEquals( "Hello world" + EOL, normalizeNewline( "Hello world" + EOL_WIN ) );
50  
51          assertEquals( EOL + "Hello world", normalizeNewline( EOL_MACOS9 + "Hello world" ) );
52          assertEquals( EOL + "Hello world", normalizeNewline( EOL_UNIX + "Hello world" ) );
53          assertEquals( EOL + "Hello world", normalizeNewline( EOL_WIN + "Hello world" ) );
54      }
55      
56      private String normalizeNewline( String  text ) throws IOException
57      {
58          InputStream in = new ByteArrayInputStream( text.getBytes() ); 
59          InputStream out = skinResourceLoader.normalizeNewline( in );
60          return IOUtil.toString( out );
61      }
62  }