001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 /**
017 *
018 */
019 package org.kuali.rice.kew.engine.node;
020
021 import static org.junit.Assert.assertEquals;
022 import static org.junit.Assert.assertFalse;
023 import static org.junit.Assert.assertNotNull;
024 import static org.junit.Assert.assertTrue;
025
026 import java.util.List;
027
028 import org.junit.Test;
029 import org.kuali.rice.kew.test.KEWTestCase;
030
031 /**
032 *
033 * Tests on functionality within the Branch class.
034 *
035 */
036 public class BranchTest extends KEWTestCase {
037
038 private Branch branch;
039
040 public BranchTest() {
041 super();
042 }
043
044 @Test public void testBranchStateIsLazyLoadable() {
045 branch = new Branch();
046 List<BranchState> branchStates = branch.getBranchState();
047 assertNotNull("new branchStates should not be null", branchStates);
048 assertEquals("new branchStates should be empty", 0, branchStates.size());
049
050 // it should fail with out of bounds error if you try to access an invalid
051 // index directly on the get() method of the List, as we're not using a lazy list
052 boolean errorThrown = false;
053 try {
054 branchStates.get(0);
055 }
056 catch (IndexOutOfBoundsException e) {
057 errorThrown = true;
058 }
059 assertTrue("An IndexOutOfBoundsException should have been thrown", errorThrown);
060
061 // it should not fail if using the getBranchStates(int index) method
062 errorThrown = false;
063 try {
064 branch.getDocBranchState(0);
065 }
066 catch (Exception e) {
067 errorThrown = true;
068 }
069 assertFalse("No exception should have been thrown", errorThrown);
070 assertEquals("There should now be one element in the list (empty)", 1, branchStates.size());
071 }
072
073 }