org.eclipse.core.tests.resources
Class ResourceDeltaVerifier

java.lang.Object
  extended by junit.framework.Assert
      extended by org.eclipse.core.tests.resources.ResourceDeltaVerifier
All Implemented Interfaces:
java.util.EventListener, IResourceChangeListener
Direct Known Subclasses:
CharsetTest.CharsetVerifier

public class ResourceDeltaVerifier
extends junit.framework.Assert
implements IResourceChangeListener

Verifies the state of an IResourceDelta by comparing it with a client's expectations. The delta is considered valid if it contains exactly the set of changes expected by the client, and parents of those changes.

Example usage: ResourceDeltaVerifier verifier = new ResourceDeltaComparer(); IResourceChangeListener listener = (IResourceChangeListener)verifier; IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject proj = workspace.getRoot().getProject("MyProject"); // Assume the project is accessible workspace.addResourceChangeListener(listener); verifier.addExpectedChange(proj, REMOVED, 0); try { proj.delete(true, true, null); } catch(CoreException e){ fail("1.0", e); } assert("2.0 "+verifier.getMessage(), verifier.isDeltaValid());


Constructor Summary
ResourceDeltaVerifier()
           
 
Method Summary
 void addExpectedChange(IResource[] resources, int status, int changeFlags)
           
 void addExpectedChange(IResource resource, int status, int changeFlags)
          Signals to the comparer that the given resource is expected to change in the specified way.
 void addExpectedChange(IResource resource, int status, int changeFlags, org.eclipse.core.runtime.IPath movedFromPath, org.eclipse.core.runtime.IPath movedToPath)
          Signals to the comparer that the given resource is expected to change in the specified way.
 void addExpectedChange(IResource resource, IResource topLevelParent, int status, int changeFlags)
          Signals to the comparer that the given resource is expected to change in the specified way.
 void addExpectedChange(IResource resource, IResource topLevelParent, int status, int changeFlags, org.eclipse.core.runtime.IPath movedFromPath, org.eclipse.core.runtime.IPath movedToPath)
          Signals to the comparer that the given resource is expected to change in the specified way.
 void addExpectedDeletion(IResource resource)
          Adds an expected deletion for the given resource and all children.
 java.lang.String getMessage()
          Returns a message that describes the result of the resource delta verification checks.
 boolean hasBeenNotified()
          Returns true if this verifier has received a delta notification since the last reset, and false otherwise.
 boolean hasExpectedChanges()
          Returns true if this verifier currently has an expected changes, and false otherwise.
 boolean isDeltaValid()
          Returns whether the resource delta passed all verification checks.
static void main(java.lang.String[] args)
          Tests message formatting.
 void reset()
          Resets the listener to its initial state.
 void resourceChanged(IResourceChangeEvent e)
          Part of the IResourceChangedListener interface.
 void verifyDelta(IResourceDelta delta)
          Compares the given delta with the expected changes.
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceDeltaVerifier

public ResourceDeltaVerifier()
Method Detail

addExpectedChange

public void addExpectedChange(IResource[] resources,
                              int status,
                              int changeFlags)
See Also:
addExpectedChange(org.eclipse.core.resources.IResource[], int, int)

addExpectedDeletion

public void addExpectedDeletion(IResource resource)
Adds an expected deletion for the given resource and all children.


addExpectedChange

public void addExpectedChange(IResource resource,
                              int status,
                              int changeFlags)
Signals to the comparer that the given resource is expected to change in the specified way. The change flags should be set to zero if no change is expected.

Parameters:
resource - the resource that is expected to change
status - the type of change (ADDED, REMOVED, CHANGED)
changeFlags - the type of change (CONTENT, SYNC, etc)
See Also:
IResourceConstants

addExpectedChange

public void addExpectedChange(IResource resource,
                              int status,
                              int changeFlags,
                              org.eclipse.core.runtime.IPath movedFromPath,
                              org.eclipse.core.runtime.IPath movedToPath)
Signals to the comparer that the given resource is expected to change in the specified way. The change flags should be set to zero if no change is expected.

Parameters:
resource - the resource that is expected to change
status - the type of change (ADDED, REMOVED, CHANGED)
changeFlags - the type of change (CONTENT, SYNC, etc)
movedPath - or null
See Also:
IResourceConstants

addExpectedChange

public void addExpectedChange(IResource resource,
                              IResource topLevelParent,
                              int status,
                              int changeFlags)
Signals to the comparer that the given resource is expected to change in the specified way. The change flags should be set to zero if no change is expected.

Parameters:
resource - the resource that is expected to change
topLevelParent - Do not added expected changes above this parent
status - the type of change (ADDED, REMOVED, CHANGED)
changeFlags - the type of change (CONTENT, SYNC, etc)
movedPath - or null
See Also:
IResourceConstants

addExpectedChange

public void addExpectedChange(IResource resource,
                              IResource topLevelParent,
                              int status,
                              int changeFlags,
                              org.eclipse.core.runtime.IPath movedFromPath,
                              org.eclipse.core.runtime.IPath movedToPath)
Signals to the comparer that the given resource is expected to change in the specified way. The change flags should be set to zero if no change is expected.

Parameters:
resource - the resource that is expected to change
topLevelParent - Do not added expected changes above this parent
status - the type of change (ADDED, REMOVED, CHANGED)
changeFlags - the type of change (CONTENT, SYNC, etc)
movedPath - or null
See Also:
IResourceConstants

getMessage

public java.lang.String getMessage()
Returns a message that describes the result of the resource delta verification checks.


hasBeenNotified

public boolean hasBeenNotified()
Returns true if this verifier has received a delta notification since the last reset, and false otherwise.


hasExpectedChanges

public boolean hasExpectedChanges()
Returns true if this verifier currently has an expected changes, and false otherwise.


isDeltaValid

public boolean isDeltaValid()
Returns whether the resource delta passed all verification checks.


main

public static void main(java.lang.String[] args)
Tests message formatting. This main method does not represent the intended use of the ResourceDeltaVerifier. See the class comment for instructions on using the verifier.


reset

public void reset()
Resets the listener to its initial state.


resourceChanged

public void resourceChanged(IResourceChangeEvent e)
Part of the IResourceChangedListener interface.

Specified by:
resourceChanged in interface IResourceChangeListener
Parameters:
e - the resource change event
See Also:
IResourceChangedListener

verifyDelta

public void verifyDelta(IResourceDelta delta)
Compares the given delta with the expected changes. Recursively compares child deltas.