View Javadoc

1   package org.apache.torque.util.functions;
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 junit.framework.TestCase;
23  
24  import org.apache.torque.ColumnImpl;
25  
26  /**
27   * Tests the Avg class.
28   *
29   * @version $Id: AvgTest.java 1336994 2012-05-11 01:09:05Z tfischer $
30   */
31  public class AvgTest extends TestCase
32  {
33      /**
34       * Tests the avg constructor with a column returns the correct SQL.
35       */
36      public void testAvg()
37      {
38          Avg avg = new Avg(new ColumnImpl("myColumn"));
39          assertEquals("AVG(myColumn)", avg.getSqlExpression());
40      }
41  
42      /**
43       * Tests the avg constructor with a column returns the correct SQL.
44       */
45      public void testAvgFromString()
46      {
47          Avg avg = new Avg("myColumn");
48          assertEquals("AVG(myColumn)", avg.getSqlExpression());
49      }
50  
51      /**
52       * Tests the avg constructor with distinct returns the correct SQL.
53       */
54      public void testAvgWithDistinct()
55      {
56          Avg avg = new Avg(new ColumnImpl("myColumn"), true);
57          assertEquals("AVG(DISTINCT myColumn)", avg.getSqlExpression());
58      }
59  
60      /**
61       * tests that setFunction throws a
62       */
63      public void testSetFunction()
64      {
65          Avg avg = new Avg(new ColumnImpl("myColumn"));
66          try
67          {
68              avg.setFunction("other");
69              fail("Exception expected");
70          }
71          catch (UnsupportedOperationException e)
72          {
73              assertEquals(
74                      "The function name may not be changed.",
75                      e.getMessage());
76          }
77      }
78  }