Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24760/src/org/rubypeople/rdt/internal/core Modified Files: TC_SymbolIndexResourceEventListener.java Added Files: ShamMassIndexUpdater.java ShamResourceChangeEvent.java ShamResourceDelta.java Log Message: Update SymbolIndex when a new project is opened. --- NEW FILE: ShamResourceChangeEvent.java --- /* * Author: David Corbin * * Copyright (c) 2005 RubyPeople. * * This file is part of the Ruby Development Tools (RDT) plugin for eclipse. * RDT is subject to the "Common Public License (CPL) v 1.0". You may not use * RDT except in compliance with the License. For further information see * org.rubypeople.rdt/rdt.license. */ package org.rubypeople.rdt.internal.core; import org.eclipse.core.resources.IMarkerDelta; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceDelta; public class ShamResourceChangeEvent implements IResourceChangeEvent { private final int type; private final IResourceDelta delta; public ShamResourceChangeEvent(int type, IResourceDelta delta) { this.type = type; this.delta = delta; } public IMarkerDelta[] findMarkerDeltas(String type, boolean includeSubtypes) { return null; } public int getBuildKind() { return 0; } public IResourceDelta getDelta() { return delta; } public IResource getResource() { return null; } public Object getSource() { return null; } public int getType() { return type; } } Index: TC_SymbolIndexResourceEventListener.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/TC_SymbolIndexResourceEventListener.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TC_SymbolIndexResourceEventListener.java 16 Oct 2005 23:52:44 -0000 1.1 --- TC_SymbolIndexResourceEventListener.java 19 Oct 2005 00:33:05 -0000 1.2 *************** *** 1,10 **** package org.rubypeople.rdt.internal.core; import junit.framework.TestCase; public class TC_SymbolIndexResourceEventListener extends TestCase { ! public void testSomething() throws Exception { } } --- 1,106 ---- + /* + * Author: David Corbin + * + * Copyright (c) 2005 RubyPeople. + * + * This file is part of the Ruby Development Tools (RDT) plugin for eclipse. + * RDT is subject to the "Common Public License (CPL) v 1.0". You may not use + * RDT except in compliance with the License. For further information see + * org.rubypeople.rdt/rdt.license. + */ package org.rubypeople.rdt.internal.core; import junit.framework.TestCase; + import org.eclipse.core.resources.IResource; + import org.eclipse.core.resources.IResourceChangeEvent; + import org.eclipse.core.resources.IResourceDelta; + import org.eclipse.core.runtime.Path; + import org.rubypeople.eclipse.shams.resources.ShamProject; + import org.rubypeople.eclipse.shams.resources.ShamResource; + import org.rubypeople.rdt.internal.core.util.ListUtil; + public class TC_SymbolIndexResourceEventListener extends TestCase { ! ! private ShamMassIndexUpdater massIndexUpdater; ! private SymbolIndexResourceChangeListener listener; ! private ShamProject project; ! private ShamResourceDelta parentDelta; ! private ShamResource resource; ! ! public void setUp() { ! massIndexUpdater = new ShamMassIndexUpdater(); ! listener = new SymbolIndexResourceChangeListener(massIndexUpdater); ! project = new ShamProject("test1"); ! resource = new ShamResource(new Path("test1/file1")); ! parentDelta = new ShamResourceDelta(); ! } ! ! public void testSimpleProjectOpen() throws Exception { ! parentDelta.addChildren(createDelta(project)); ! ! ShamResourceChangeEvent event = ! new ShamResourceChangeEvent(IResourceChangeEvent.POST_CHANGE, parentDelta); ! ! listener.resourceChanged(event); ! ! massIndexUpdater.assertProjectsUpdated(ListUtil.create(project)); ! } ! ! public void testWithoutProject() throws Exception { ! parentDelta.addChildren(createDelta(resource)); ! ! ShamResourceChangeEvent event = ! new ShamResourceChangeEvent(IResourceChangeEvent.POST_CHANGE, parentDelta); ! ! listener.resourceChanged(event); ! ! massIndexUpdater.assertUpdateProjectsNotCalled(); ! } ! ! public void testNotAPostChange() throws Exception { ! parentDelta.addChildren(createDelta(project)); ! ! ShamResourceChangeEvent event = ! new ShamResourceChangeEvent(IResourceChangeEvent.POST_BUILD, parentDelta); ! ! listener.resourceChanged(event); ! ! massIndexUpdater.assertUpdateProjectsNotCalled(); ! } ! ! public void testNotADeltaChange() throws Exception { ! ShamResourceDelta projectDelta = createDelta(project); ! projectDelta.setKind(IResourceDelta.MOVED_FROM); ! parentDelta.addChildren(projectDelta); ! ! ShamResourceChangeEvent event = ! new ShamResourceChangeEvent(IResourceChangeEvent.POST_CHANGE, parentDelta); + listener.resourceChanged(event); + + massIndexUpdater.assertUpdateProjectsNotCalled(); + } + + public void testNotAOpen() throws Exception { + ShamResourceDelta projectDelta = createDelta(project); + projectDelta.setFlags(IResourceDelta.MARKERS); + parentDelta.addChildren(projectDelta); + + ShamResourceChangeEvent event = + new ShamResourceChangeEvent(IResourceChangeEvent.POST_CHANGE, parentDelta); + + listener.resourceChanged(event); + + massIndexUpdater.assertUpdateProjectsNotCalled(); + } + + private ShamResourceDelta createDelta(IResource resource) { + ShamResourceDelta delta = new ShamResourceDelta(); + delta.addResource(resource); + delta.setKind(IResourceDelta.CHANGED); + delta.setFlags(IResourceDelta.OPEN | IResourceDelta.MARKERS); + return delta; } } --- NEW FILE: ShamResourceDelta.java --- /* * Author: David Corbin * * Copyright (c) 2005 RubyPeople. * * This file is part of the Ruby Development Tools (RDT) plugin for eclipse. * RDT is subject to the "Common Public License (CPL) v 1.0". You may not use * RDT except in compliance with the License. For further information see * org.rubypeople.rdt/rdt.license. */ package org.rubypeople.rdt.internal.core; import java.util.ArrayList; import java.util.List; import org.eclipse.core.resources.IMarkerDelta; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; class ShamResourceDelta implements IResourceDelta { private List children = new ArrayList(); private IResource resource; private int kind; private int flags; public void accept(IResourceDeltaVisitor visitor) throws CoreException { } public void accept(IResourceDeltaVisitor visitor, boolean includePhantoms) throws CoreException { } public void accept(IResourceDeltaVisitor visitor, int memberFlags) throws CoreException { } public IResourceDelta findMember(IPath path) { return null; } public IResourceDelta[] getAffectedChildren() { return (IResourceDelta[]) children.toArray(new IResourceDelta[0]); } public IResourceDelta[] getAffectedChildren(int kindMask) { return null; } public IResourceDelta[] getAffectedChildren(int kindMask, int memberFlags) { return null; } public int getFlags() { return flags; } public IPath getFullPath() { return null; } public int getKind() { return kind; } public IMarkerDelta[] getMarkerDeltas() { return null; } public IPath getMovedFromPath() { return null; } public IPath getMovedToPath() { return null; } public IPath getProjectRelativePath() { return null; } public IResource getResource() { return resource; } public Object getAdapter(Class adapter) { return null; } public void addResource(IResource resource) { this.resource = resource; } public void addChildren(IResourceDelta delta) { children.add(delta); } public void setKind(int kind) { this.kind = kind; } public void setFlags(int flags) { this.flags = flags; } } --- NEW FILE: ShamMassIndexUpdater.java --- /* * Author: David Corbin * * Copyright (c) 2005 RubyPeople. * * This file is part of the Ruby Development Tools (RDT) plugin for eclipse. * RDT is subject to the "Common Public License (CPL) v 1.0". You may not use * RDT except in compliance with the License. For further information see * org.rubypeople.rdt/rdt.license. */ package org.rubypeople.rdt.internal.core; import java.util.Collection; import java.util.List; import junit.framework.Assert; import org.rubypeople.rdt.internal.core.builder.MassIndexUpdater; public class ShamMassIndexUpdater extends MassIndexUpdater { private Collection projectsArg; public ShamMassIndexUpdater() { super(null); } public void assertProjectsUpdated(Collection expectedProjects) { Assert.assertEquals(expectedProjects, projectsArg); } public void updateProjects(List projects) { projectsArg = projects; } public void assertUpdateProjectsNotCalled() { Assert.assertNull("Unexpected call to updateProjects", projectsArg); } } |