View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.jxpath.ri.model;
18  
19  import java.util.Collections;
20  
21  import org.apache.commons.jxpath.JXPathContext;
22  import org.apache.commons.jxpath.JXPathTestCase;
23  
24  /**
25   * Be sure empty lists/sets/arrays work.
26   * @author mbenson
27   * @version $Revision: 652845 $ $Date: 2008-05-02 19:46:46 +0200 (Fr, 02 Mai 2008) $
28   */
29  public class EmptyCollectionTest extends JXPathTestCase {
30      public static class HasChild {
31          private Object child;
32  
33          /**
34           * Construct a new EmptyCollectionTest.HasChild instance.
35           */
36          public HasChild(Object child) {
37              this.child = child;
38          }
39  
40          public Object getChild() {
41              return child;
42          }
43      }
44  
45      public void testEmptyList() {
46          assertXPathPointerIterator(JXPathContext.newContext(Collections.EMPTY_LIST), "/*",
47                  Collections.EMPTY_LIST);
48      }
49  
50      public void testEmptyArray() {
51          assertXPathPointerIterator(JXPathContext.newContext(new Object[0]), "/*", list());
52      }
53  
54      public void testEmptySet() {
55          assertXPathPointerIterator(JXPathContext.newContext(Collections.EMPTY_SET), "/*",
56                  Collections.EMPTY_SET);
57      }
58  
59      public void testEmptyChildList() {
60          assertXPathPointerIterator(JXPathContext.newContext(new HasChild(Collections.EMPTY_LIST)),
61                  "/child/*", Collections.EMPTY_LIST);
62      }
63  
64      public void testEmptyChildArray() {
65          assertXPathPointerIterator(JXPathContext.newContext(new HasChild(new Object[0])),
66                  "/child/*", list());
67      }
68  
69      public void testEmptyChildSet() {
70          assertXPathPointerIterator(JXPathContext.newContext(new HasChild(Collections.EMPTY_SET)),
71                  "/child/*", Collections.EMPTY_SET);
72      }
73  }