Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8ec7c2cb1aaaf7fdd4e582c3af0b4d2013f4cca5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*******************************************************************************
 * Copyright (c) 2011 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.branch.management.test.purge;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import junit.framework.Assert;
import org.eclipse.osee.framework.branch.management.purge.MultiBranchProvider;
import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchProvider;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.cache.BranchFilter;
import org.junit.Test;

/**
 * @author John Misinco
 */
public class MultiBranchProviderTest {

   @Test
   public void testGetBranchesRecursive() throws OseeCoreException {
      BranchFilter filter = new BranchFilter();
      filter.setNegatedBranchTypes(BranchType.BASELINE);
      Set<Branch> branchRoots = new HashSet<Branch>();

      Collection<Branch> testBranchesA = MockBranchProvider.createTestBranches();
      Collection<Branch> testBranchesB = MockBranchProvider.createTestBranches();

      branchRoots.add(MockBranchProvider.getRootBranch(testBranchesA));
      branchRoots.add(MockBranchProvider.getRootBranch(testBranchesB));

      MultiBranchProvider provider = new MultiBranchProvider(true, branchRoots, filter);
      int numBranches = provider.getBranches().size();
      int expectedSize = testBranchesA.size() + testBranchesB.size();
      Assert.assertEquals(expectedSize, numBranches);
   }

   @Test
   public void testGetBranchesNonRecursive() throws OseeCoreException {
      BranchFilter filter = new BranchFilter();
      filter.setNegatedBranchTypes(BranchType.BASELINE);

      Collection<Branch> testBranches = MockBranchProvider.createTestBranches();

      MultiBranchProvider provider1 =
         new MultiBranchProvider(false, Collections.singleton(MockBranchProvider.getRootBranch(testBranches)), filter);
      int numBranches = provider1.getBranches().size();
      Assert.assertEquals(1, numBranches);

      Set<Branch> branches = new HashSet<Branch>(MockBranchProvider.createTestBranches());
      MultiBranchProvider provider2 = new MultiBranchProvider(false, branches, filter);
      numBranches = provider2.getBranches().size();
      Assert.assertEquals(branches.size(), numBranches);
   }

   @Test(expected = OseeCoreException.class)
   public void testGetBranchesException() throws OseeCoreException {
      MultiBranchProvider provider = new MultiBranchProvider(true, null, null);
      provider.getBranches().size();
   }
}

Back to the top