| author | jmisinco | 2011-05-19 14:53:54 (EDT) |
|---|---|---|
| committer | Ryan D. Brooks | 2011-05-19 14:53:54 (EDT) |
| commit | fb6f6d04469e126dfe133bffcc3bacf0842564f0 (patch) (side-by-side diff) | |
| tree | 3fb95e0ea8649af3dcb0d3601064edb6dba38c6f | |
| parent | 3b525e8167a5acf90fb18363c02209f8c19b5e05 (diff) | |
| download | org.eclipse.osee-fb6f6d04469e126dfe133bffcc3bacf0842564f0.zip org.eclipse.osee-fb6f6d04469e126dfe133bffcc3bacf0842564f0.tar.gz org.eclipse.osee-fb6f6d04469e126dfe133bffcc3bacf0842564f0.tar.bz2 | |
bug[bgz_342607]: Fix DeletedBranchProvider ConcurrentModificationException
4 files changed, 41 insertions, 22 deletions
diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java index a9050b7..bc45b31 100644 --- a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java +++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java @@ -24,16 +24,12 @@ import org.eclipse.osee.framework.jdk.core.util.GUID; */ public final class MockBranchProvider implements IBranchesProvider { - private Branch root; - private final Collection<Branch> branches = new ArrayList<Branch>(); + private final static String ROOT_BRANCH_NAME = "ROOT"; - public MockBranchProvider() throws OseeCoreException { - initializeData(); - } - - private void initializeData() throws OseeCoreException { + public static Collection<Branch> createTestBranches() throws OseeCoreException { + Collection<Branch> branches = new ArrayList<Branch>(); //create a root branch - root = new Branch(GUID.create(), "root", BranchType.SYSTEM_ROOT, BranchState.COMMITTED, false); + Branch root = new Branch(GUID.create(), ROOT_BRANCH_NAME, BranchType.SYSTEM_ROOT, BranchState.COMMITTED, false); //add a child to root (parent) Branch parent = new Branch(GUID.create(), "parent", BranchType.SYSTEM_ROOT, BranchState.CREATED, false); @@ -76,14 +72,21 @@ public final class MockBranchProvider implements IBranchesProvider { branches.add(child3); branches.add(grandChild1); branches.add(parent); + + return branches; } - public Branch getRootBranch() { - return root; + public static Branch getRootBranch() throws OseeCoreException { + for (Branch branch : MockBranchProvider.createTestBranches()) { + if (branch.getName().equals(ROOT_BRANCH_NAME)) { + return branch; + } + } + return null; } @Override - public Collection<Branch> getBranches() { - return branches; + public Collection<Branch> getBranches() throws OseeCoreException { + return MockBranchProvider.createTestBranches(); } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/DeletedBranchProviderTest.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/DeletedBranchProviderTest.java index 2bee8e9..be42878 100644 --- a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/DeletedBranchProviderTest.java +++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/DeletedBranchProviderTest.java @@ -14,6 +14,9 @@ import java.util.Collection; import junit.framework.Assert; import org.eclipse.osee.framework.branch.management.purge.DeletedBranchProvider; import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchProvider; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +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.BranchCache; @@ -25,19 +28,26 @@ import org.junit.Test; */ public final class DeletedBranchProviderTest { + private int expectedResult(Collection<Branch> branches) { + int result = 0; + for (Branch branch : branches) { + if (branch.getBranchState() == BranchState.DELETED && branch.getArchiveState() == BranchArchivedState.ARCHIVED && !(branch.getBranchType() == BranchType.BASELINE)) { + result++; + } + } + return result; + } + @Test public void testGetBranches() throws OseeCoreException { - Collection<Branch> branches; - - MockBranchProvider mbp = new MockBranchProvider(); BranchCache mockCache = new BranchCache(new MockOseeDataAccessor<Branch>()); - branches = mbp.getBranches(); + Collection<Branch> branches = MockBranchProvider.createTestBranches(); mockCache.cache(branches.toArray(new Branch[branches.size()])); DeletedBranchProvider provider = new DeletedBranchProvider(mockCache); int numBranches = provider.getBranches().size(); - Assert.assertEquals(2, numBranches); + Assert.assertEquals(expectedResult(branches), numBranches); } @Test(expected = OseeCoreException.class) diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java index 7d9237d..d6eefe3 100644 --- a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java +++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java @@ -23,15 +23,18 @@ import org.junit.Test; */ public class RecursiveBranchProviderTest { + private int getExpectedNumberOfBranches() throws OseeCoreException { + return MockBranchProvider.createTestBranches().size(); + } + @Test public void testGetBranches() throws OseeCoreException { - MockBranchProvider mbp = new MockBranchProvider(); BranchFilter filter = new BranchFilter(); filter.setNegatedBranchTypes(BranchType.BASELINE); - RecursiveBranchProvider provider = new RecursiveBranchProvider(mbp.getRootBranch(), filter); + RecursiveBranchProvider provider = new RecursiveBranchProvider(MockBranchProvider.getRootBranch(), filter); int numBranches = provider.getBranches().size(); - Assert.assertEquals(numBranches, 8); + Assert.assertEquals(getExpectedNumberOfBranches(), numBranches); } @Test(expected = OseeCoreException.class) diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/DeletedBranchProvider.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/DeletedBranchProvider.java index c581df7..5eb712b 100644 --- a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/DeletedBranchProvider.java +++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/DeletedBranchProvider.java @@ -11,6 +11,7 @@ package org.eclipse.osee.framework.branch.management.purge; import java.util.Collection; +import java.util.LinkedHashSet; import java.util.List; import org.eclipse.osee.framework.core.enums.BranchArchivedState; import org.eclipse.osee.framework.core.enums.BranchState; @@ -39,10 +40,12 @@ public final class DeletedBranchProvider implements IBranchesProvider { branchFilter.setNegatedBranchTypes(BranchType.BASELINE); List<Branch> branches = branchCache.getBranches(branchFilter); + Collection<Branch> branchesToReturn = new LinkedHashSet<Branch>(); + branchesToReturn.addAll(branches); for (Branch branch : branches) { - branch.getChildBranches(branches, true, branchFilter); + branch.getChildBranches(branchesToReturn, true, branchFilter); } - return branches; + return branchesToReturn; } }
\ No newline at end of file |

