View Javadoc

1   package org.apache.torque.generator.outlet.java;
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 static org.junit.Assert.assertEquals;
23  
24  import org.apache.torque.generator.GeneratorException;
25  import org.apache.torque.generator.outlet.OutletResult;
26  import org.apache.torque.generator.qname.QualifiedName;
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  /**
31   * Component tests for the NewlineOutlet.
32   */
33  public class NewlineOutletTest
34  {
35      /** System under test. */
36      private NewlineOutlet newlineOutlet;
37  
38      @Before
39      public void setUp()
40      {
41          this.newlineOutlet = new NewlineOutlet(new QualifiedName(
42                  "org.apache.torque.generator.newlineOutlet"));
43      }
44  
45      @Test
46      public void testDefault() throws GeneratorException
47      {
48          OutletResult result = newlineOutlet.execute(null);
49          assertEquals("\n", result.getStringResult());
50      }
51  
52      @Test
53      public void testWindowsStyle() throws GeneratorException
54      {
55          newlineOutlet.setWindowsStyle(true);
56          OutletResult result = newlineOutlet.execute(null);
57          assertEquals("\r\n", result.getStringResult());
58      }
59  
60      @Test()
61      public void testCountZero() throws GeneratorException
62      {
63          newlineOutlet.setCount(0);
64          OutletResult result = newlineOutlet.execute(null);
65          assertEquals("", result.getStringResult());
66      }
67  
68      @Test(expected = GeneratorException.class)
69      public void testCountLessThanZero() throws GeneratorException
70      {
71          newlineOutlet.setCount(-1);
72          OutletResult result = newlineOutlet.execute(null);
73          assertEquals("\n", result.getStringResult());
74      }
75  
76      @Test()
77      public void testCountFive() throws GeneratorException
78      {
79          newlineOutlet.setCount(5);
80          OutletResult result = newlineOutlet.execute(null);
81          assertEquals("\n\n\n\n\n", result.getStringResult());
82      }
83  }