View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /**
17   * 
18   */
19  package org.kuali.rice.kew.engine.node;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertFalse;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertTrue;
25  
26  import java.util.List;
27  
28  import org.junit.Test;
29  import org.kuali.rice.kew.test.KEWTestCase;
30  
31  /**
32   * 
33   * Tests on functionality within the Branch class.
34   *
35   */
36  public class BranchTest extends KEWTestCase {
37  
38      private Branch branch;
39      
40      public BranchTest() {
41          super();
42      }
43      
44      @Test public void testBranchStateIsLazyLoadable() {
45          branch = new Branch();
46          List<BranchState> branchStates = branch.getBranchState();
47          assertNotNull("new branchStates should not be null", branchStates);
48          assertEquals("new branchStates should be empty", 0, branchStates.size());
49          
50          //  it should fail with out of bounds error if you try to access an invalid 
51          // index directly on the get() method of the List, as we're not using a lazy list
52          boolean errorThrown = false;
53          try {
54              branchStates.get(0);
55          }
56          catch (IndexOutOfBoundsException e) {
57              errorThrown = true;
58          }
59          assertTrue("An IndexOutOfBoundsException should have been thrown", errorThrown);
60          
61          //  it should not fail if using the getBranchStates(int index) method
62          errorThrown = false;
63          try {
64              branch.getDocBranchState(0);
65          }
66          catch (Exception e) {
67              errorThrown = true;
68          }
69          assertFalse("No exception should have been thrown", errorThrown);
70          assertEquals("There should now be one element in the list (empty)", 1, branchStates.size());
71      }
72      
73  }