View Javadoc

1   /*
2    * $Id: PrivateAccessorTest.java 1188000 2011-10-23 23:10:24Z mcucchiara $
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  package org.apache.commons.ognl.test;
21  
22  import org.apache.commons.ognl.DefaultMemberAccess;
23  import org.apache.commons.ognl.test.objects.Root;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  import org.junit.runners.Parameterized;
28  import org.junit.runners.Parameterized.Parameters;
29  
30  import java.util.ArrayList;
31  import java.util.Collection;
32  
33  @RunWith(value = Parameterized.class)
34  public class PrivateAccessorTest
35      extends OgnlTestCase
36  {
37  
38      private static Root ROOT = new Root();
39  
40      private static Object[][] TESTS = {
41          // Using private get/set methods
42          { ROOT, "getPrivateAccessorIntValue()", new Integer( 67 ) },
43          { ROOT, "privateAccessorIntValue", new Integer( 67 ) },
44          { ROOT, "privateAccessorIntValue", new Integer( 67 ), new Integer( 100 ) },
45          { ROOT, "privateAccessorIntValue2", new Integer( 67 ) },
46          { ROOT, "privateAccessorIntValue2", new Integer( 67 ), new Integer( 100 ) },
47          { ROOT, "privateAccessorIntValue3", new Integer( 67 ) },
48          { ROOT, "privateAccessorIntValue3", new Integer( 67 ), new Integer( 100 ) },
49          { ROOT, "privateAccessorBooleanValue", Boolean.TRUE },
50          { ROOT, "privateAccessorBooleanValue", Boolean.TRUE, Boolean.FALSE }, };
51  
52      /*
53       * =================================================================== Public static methods
54       * ===================================================================
55       */
56      @Parameters
57      public static Collection<Object[]> data()
58      {
59          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
60          for ( int i = 0; i < TESTS.length; i++ )
61          {
62              Object[] tmp = new Object[6];
63              tmp[0] = TESTS[i][1];
64              tmp[1] = TESTS[i][0];
65              tmp[2] = TESTS[i][1];
66  
67              switch ( TESTS[i].length )
68              {
69                  case 3:
70                      tmp[3] = TESTS[i][2];
71                      break;
72  
73                  case 4:
74                      tmp[3] = TESTS[i][2];
75                      tmp[4] = TESTS[i][3];
76                      break;
77  
78                  case 5:
79                      tmp[3] = TESTS[i][2];
80                      tmp[4] = TESTS[i][3];
81                      tmp[5] = TESTS[i][4];
82                      break;
83  
84                  default:
85                      throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
86              }
87  
88              data.add( tmp );
89          }
90          return data;
91      }
92  
93      /*
94       * =================================================================== Constructors
95       * ===================================================================
96       */
97      public PrivateAccessorTest( String name, Object root, String expressionString, Object expectedResult,
98                                  Object setValue, Object expectedAfterSetResult )
99      {
100         super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
101     }
102 
103     /*
104      * =================================================================== Overridden methods
105      * ===================================================================
106      */
107     @Before
108     @Override
109     public void setUp()
110     {
111         super.setUp();
112         _context.setMemberAccess( new DefaultMemberAccess( true ) );
113         _compileExpressions = false;
114     }
115 
116     @Test
117 
118     @Override
119     public void runTest()
120         throws Exception
121     {
122        super.runTest();
123     }
124 }