View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.model;
21  
22  import org.junit.Assert;
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  public class NodeUnitTest {
27  
28    private Node r;
29    private Node a;
30    private Node b;
31    private Node c;
32    private Node x;
33    private Node y;
34    private Node pi;
35  
36    /**
37     * * --o r (0)
38     * *   |
39     * *   +--o a (0,0)
40     * *   |
41     * *   +--o b (0,1)
42     * *   |   |
43     * *   |   +--o x (0,1,0)
44     * *   |   |
45     * *   |   +--o y (0,1,1)
46     * *   |      |
47     * *   |      +--o π (0,1,1,0)
48     * *   |
49     * *   +--o c (0,1,1,0)
50     */
51    @Before
52    public void setUp() {
53  
54      r = new Node();
55      a = new Node();
56      b = new Node();
57      c = new Node();
58      x = new Node();
59      y = new Node();
60      pi = new Node();
61  
62      r.add(a);
63      r.add(b);
64      r.add(c);
65  
66      b.add(x);
67      b.add(y);
68  
69      y.add(pi);
70  
71    }
72  
73    @Test
74    public void testIsRoot() {
75      Assert.assertTrue(r.isRoot());
76      Assert.assertFalse(a.isRoot());
77      Assert.assertFalse(b.isRoot());
78      Assert.assertFalse(c.isRoot());
79      Assert.assertFalse(x.isRoot());
80      Assert.assertFalse(y.isRoot());
81      Assert.assertFalse(pi.isRoot());
82    }
83  
84    @Test
85    public void testGetChildCount() {
86      Assert.assertEquals(3, r.getChildCount());
87      Assert.assertEquals(0, a.getChildCount());
88      Assert.assertEquals(2, b.getChildCount());
89      Assert.assertEquals(0, c.getChildCount());
90      Assert.assertEquals(0, x.getChildCount());
91      Assert.assertEquals(1, y.getChildCount());
92      Assert.assertEquals(0, pi.getChildCount());
93    }
94  
95    @Test
96    public void testHasNextSibling() {
97      Assert.assertFalse(r.hasNextSibling());
98      Assert.assertTrue(a.hasNextSibling());
99      Assert.assertTrue(b.hasNextSibling());
100     Assert.assertFalse(c.hasNextSibling());
101     Assert.assertTrue(x.hasNextSibling());
102     Assert.assertFalse(y.hasNextSibling());
103     Assert.assertFalse(pi.hasNextSibling());
104   }
105 
106 }