View Javadoc

1   /*
2    * $Id: MapCreationTest.java 1104080 2011-05-17 09:22:09Z 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.test.objects.Root;
23  import org.junit.runner.RunWith;
24  import org.junit.runners.Parameterized;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  import java.util.*;
28  
29  @RunWith(value = Parameterized.class)
30  public class MapCreationTest
31      extends OgnlTestCase
32  {
33  
34      private static Root ROOT = new Root();
35  
36      private static Map fooBarMap1;
37  
38      private static Map fooBarMap2;
39  
40      private static Map fooBarMap3;
41  
42      private static Map fooBarMap4;
43  
44      private static Map fooBarMap5;
45  
46      static
47      {
48          fooBarMap1 = new HashMap();
49          fooBarMap1.put( "foo", "bar" );
50          fooBarMap2 = new HashMap();
51          fooBarMap2.put( "foo", "bar" );
52          fooBarMap2.put( "bar", "baz" );
53          fooBarMap3 = new HashMap();
54          fooBarMap3.put( "foo", null );
55          fooBarMap3.put( "bar", "baz" );
56          fooBarMap4 = new LinkedHashMap();
57          fooBarMap4.put( "foo", "bar" );
58          fooBarMap4.put( "bar", "baz" );
59          fooBarMap5 = new TreeMap();
60          fooBarMap5.put( "foo", "bar" );
61          fooBarMap5.put( "bar", "baz" );
62      }
63  
64      private static Object[][] TESTS = {
65          // Map creation
66          { ROOT, "#{ \"foo\" : \"bar\" }", fooBarMap1 },
67          { ROOT, "#{ \"foo\" : \"bar\", \"bar\" : \"baz\"  }", fooBarMap2 },
68          { ROOT, "#{ \"foo\", \"bar\" : \"baz\"  }", fooBarMap3 },
69          { ROOT, "#@java.util.LinkedHashMap@{ \"foo\" : \"bar\", \"bar\" : \"baz\"  }", fooBarMap4 },
70          { ROOT, "#@java.util.TreeMap@{ \"foo\" : \"bar\", \"bar\" : \"baz\"  }", fooBarMap5 },
71  
72      };
73  
74      /*
75       * =================================================================== Public static methods
76       * ===================================================================
77       */
78      @Parameters
79      public static Collection<Object[]> data()
80      {
81          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
82          for ( int i = 0; i < TESTS.length; i++ )
83          {
84              Object[] tmp = new Object[6];
85              tmp[0] = TESTS[i][1];
86              tmp[1] = TESTS[i][0];
87              tmp[2] = TESTS[i][1];
88  
89              switch ( TESTS[i].length )
90              {
91                  case 3:
92                      tmp[3] = TESTS[i][2];
93                      break;
94  
95                  case 4:
96                      tmp[3] = TESTS[i][2];
97                      tmp[4] = TESTS[i][3];
98                      break;
99  
100                 case 5:
101                     tmp[3] = TESTS[i][2];
102                     tmp[4] = TESTS[i][3];
103                     tmp[5] = TESTS[i][4];
104                     break;
105 
106                 default:
107                     throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
108             }
109 
110             data.add( tmp );
111         }
112         return data;
113     }
114 
115     /*
116      * =================================================================== Constructors
117      * ===================================================================
118      */
119     public MapCreationTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
120                             Object expectedAfterSetResult )
121     {
122         super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
123     }
124 }