001/**
002 * Copyright 2005-2014 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 */
019package org.kuali.rice.kew.engine.node;
020
021import static org.junit.Assert.assertEquals;
022import static org.junit.Assert.assertFalse;
023import static org.junit.Assert.assertNotNull;
024import static org.junit.Assert.assertTrue;
025
026import java.util.List;
027
028import org.junit.Test;
029import org.kuali.rice.kew.test.KEWTestCase;
030
031/**
032 * 
033 * Tests on functionality within the Branch class.
034 *
035 */
036public 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}