diff options
author | Stefan Xenos | 2017-02-07 16:40:28 +0000 |
---|---|---|
committer | Stefan Xenos | 2017-02-08 01:00:57 +0000 |
commit | 5da5dd814399ab3c75a57d7bf04dcae5ea3b9cb6 (patch) | |
tree | 5431c92e1d339b3c899add0d69e1b95160b75d17 /org.eclipse.jdt.apt.tests | |
parent | 4f4c1a8568b6c8e3ef698fb900fcd735f8e63d01 (diff) | |
download | eclipse.jdt.core-5da5dd814399ab3c75a57d7bf04dcae5ea3b9cb6.tar.gz eclipse.jdt.core-5da5dd814399ab3c75a57d7bf04dcae5ea3b9cb6.tar.xz eclipse.jdt.core-5da5dd814399ab3c75a57d7bf04dcae5ea3b9cb6.zip |
Bug 511845 - FactoryPath.internalAdd takes O(n) timeI20170208-0700I20170207-2000
Change-Id: I8e1b34234195f8b2ad1dc26d6244a75fdfc68b18
Signed-off-by: Stefan Xenos <sxenos@gmail.com>
Diffstat (limited to 'org.eclipse.jdt.apt.tests')
-rw-r--r-- | org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FactoryPathTests.java | 117 | ||||
-rw-r--r-- | org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/TestAll.java | 1 |
2 files changed, 118 insertions, 0 deletions
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FactoryPathTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FactoryPathTests.java new file mode 100644 index 0000000000..0a29b34a2a --- /dev/null +++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FactoryPathTests.java @@ -0,0 +1,117 @@ +package org.eclipse.jdt.apt.tests; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.apt.core.internal.VarJarFactoryContainer; +import org.eclipse.jdt.apt.core.internal.WkspJarFactoryContainer; +import org.eclipse.jdt.apt.core.internal.util.FactoryContainer; +import org.eclipse.jdt.apt.core.internal.util.FactoryPath; +import org.eclipse.jdt.apt.core.internal.util.FactoryPathUtil; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class FactoryPathTests extends TestCase { + private FactoryPath path; + + private final String[] filesInPath = { "all/your.jar", "base.jar", "are.jar", "belong/to/us.jar", + "you/have/no/chance.jar", "to.jar", "survive.jar" }; + + public FactoryPathTests(String name) { + super(name); + } + + public static Test suite() { + return new TestSuite( FactoryPathTests.class ); + } + + @Override + protected void setUp() throws Exception { + path = new FactoryPath(); + for (String next : filesInPath) { + path.addExternalJar(new File(next)); + } + super.setUp(); + } + + public void testGetAllContainers() throws Exception { + int index = 0; + List<FactoryContainer> toIterate = new ArrayList<>(); + toIterate.addAll(path.getAllContainers().keySet()); + Collections.reverse(toIterate); + for (FactoryContainer container : toIterate) { + FactoryContainer fc = FactoryPathUtil.newExtJarFactoryContainer(new File(filesInPath[index++])); + assertEquals("Unexpected jar file", fc, container); + } + } + + public void testGetEnabledContainersOrder() throws Exception { + int index = 0; + List<FactoryContainer> toIterate = new ArrayList<>(); + toIterate.addAll(path.getEnabledContainers().keySet()); + Collections.reverse(toIterate); + for (FactoryContainer container : toIterate) { + FactoryContainer fc = FactoryPathUtil.newExtJarFactoryContainer(new File(filesInPath[index++])); + assertEquals("Unexpected jar file", fc, container); + } + } + + public void testRemoveExternalJar() throws Exception { + File toRemove = new File(filesInPath[3]); + FactoryContainer fc = FactoryPathUtil.newExtJarFactoryContainer(toRemove); + + assertTrue("Initial classpath should have contained jar", path.getAllContainers().containsKey(fc)); + + path.removeExternalJar(toRemove); + + assertFalse("Final classpath should not have contained jar", path.getAllContainers().containsKey(fc)); + } + + public void testAddRemoveVarJar() throws Exception { + IPath toAdd = new Path("/foo/bar/baz.jar"); + + path.addVarJar(toAdd); + + // Will throw an exception if the newly added jar isn't first + VarJarFactoryContainer fc = (VarJarFactoryContainer)path.getAllContainers().keySet().iterator().next(); + assertEquals(toAdd.toString(), fc.getId()); + + path.removeVarJar(toAdd); + + assertFalse("Factory path should not contain the removed jar", path.getAllContainers().containsKey(fc)); + } + + public void testAddRemoveWorkspaceJar() throws Exception { + IPath toAdd = new Path("/foo/bar/baz.jar"); + + path.addWkspJar(toAdd); + + // Will throw an exception if the newly added jar isn't first + WkspJarFactoryContainer fc = (WkspJarFactoryContainer)path.getAllContainers().keySet().iterator().next(); + assertTrue(fc.getJarFile().toString().endsWith(toAdd.toString())); + + path.removeWkspJar(toAdd); + + assertFalse("Factory path should not contain the removed jar", path.getAllContainers().containsKey(fc)); + } + + public void testSetContainers() throws Exception { + FactoryPath newPath = new FactoryPath(); + newPath.setContainers(path.getAllContainers()); + + List<FactoryContainer> toIterate = new ArrayList<>(); + toIterate.addAll(newPath.getAllContainers().keySet()); + Collections.reverse(toIterate); + int index = 0; + for (FactoryContainer container : toIterate) { + FactoryContainer fc = FactoryPathUtil.newExtJarFactoryContainer(new File(filesInPath[index++])); + assertEquals("Unexpected jar file", fc, container); + } + } +} diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/TestAll.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/TestAll.java index 0487245648..3587f3ff08 100644 --- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/TestAll.java +++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/TestAll.java @@ -42,6 +42,7 @@ public class TestAll extends TestCase { suite.addTest(ReadAnnotationTests.suite()); suite.addTest(PreferencesTests.suite()); suite.addTest(FactoryLoaderTests.suite()); + suite.addTest(FactoryPathTests.suite()); suite.addTest(ListenerTests.suite()); suite.addTest(MirrorDeclarationTests.suite()); suite.addTest(MirrorUtilTests.suite()); |