Package org.eclipse.handly.junit

## Class WorkspaceTestCase

- java.lang.Object
- - junit.framework.Assert
  - - junit.framework.TestCase
    - - org.eclipse.handly.junit.WorkspaceTestCase

- All Implemented Interfaces:
    `junit.framework.Test`
  Direct Known Subclasses:
    `NoJobsWorkspaceTestCase`

      public abstract class WorkspaceTestCase
      extends junit.framework.TestCase

  Convenient base class for test cases that operate on the Eclipse workspace.

  Provides a number of useful methods, such as `setUpProject(String)`.

  Also, in its `setUp()` and `tearDown()` methods, this class enforces some common rules for workspace tests:

  - each test starts running in a clean workspace with auto-build turned off;
  - each test is responsible for setting up the necessary workspace state;
  - after running each test, the workspace is cleaned up.

  Note that since version 1.7, there is also `NoJobsWorkspaceTestCase` that additionally ensures that no jobs will execute while a test is running, which helps avoid intermittent test failures due to unpredictable nature of resource change notifications when multiple threads access the workspace concurrently.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `WorkspaceTestCase()` | No-arg constructor to enable serialization.
    `WorkspaceTestCase​(java.lang.String name)` | Constructs a test case with the given name.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected void` | `buildWorkspace()` | Builds the workspace, waiting for build completion.
    `protected void` | `cleanUpWorkspace()` | Deletes all resources in the workspace.
    `protected org.eclipse.core.resources.IProject` | `getProject​(java.lang.String name)` | Shortcut to `getWorkspaceRoot().getProject(name)`.
    `protected org.eclipse.core.resources.IWorkspace` | `getWorkspace()` | Shortcut to `ResourcesPlugin.getWorkspace()`.
    `protected org.eclipse.core.resources.IWorkspaceRoot` | `getWorkspaceRoot()` | Shortcut to `getWorkspace().getRoot()`.
    `protected void` | `resumeJobs()` | Resumes execution of jobs.
    `protected void` | `setAutoBuilding​(boolean value)` | Sets the property "Build Automatically" for the workspace.
    `protected void` | `setUp()` | Turns auto-build off, cleans up the workspace.
    `protected org.eclipse.core.resources.IProject` | `setUpProject​(java.lang.String name)` | Creates a new project in the workspace by copying its content from the OSGi-bundle of this test case.
    `protected void` | `suspendJobs()` | Suspends execution of all jobs.
    `protected void` | `tearDown()` | Cleans up the workspace.
    `protected void` | `waitForBuildCompletion()` | Waits for build completion.

    - ### Methods inherited from class junit.framework.TestCase

      `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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### WorkspaceTestCase

          public WorkspaceTestCase()

      No-arg constructor to enable serialization. This method is not intended to be used by mere mortals without calling setName().

    - #### WorkspaceTestCase

          public WorkspaceTestCase​(java.lang.String name)

      Constructs a test case with the given name.

  - ### Method Detail

    - #### setUp

          protected void setUp()
                        throws java.lang.Exception

      Turns auto-build off, cleans up the workspace.
      Overrides:
        `setUp` in class `junit.framework.TestCase`
      Throws:
        `java.lang.Exception`

    - #### tearDown

          protected void tearDown()
                           throws java.lang.Exception

      Cleans up the workspace.
      Overrides:
        `tearDown` in class `junit.framework.TestCase`
      Throws:
        `java.lang.Exception`

    - #### getWorkspace

          protected final org.eclipse.core.resources.IWorkspace getWorkspace()

      Shortcut to `ResourcesPlugin.getWorkspace()`.

    - #### getWorkspaceRoot

          protected final org.eclipse.core.resources.IWorkspaceRoot getWorkspaceRoot()

      Shortcut to `getWorkspace().getRoot()`.

    - #### getProject

          protected final org.eclipse.core.resources.IProject getProject​(java.lang.String name)

      Shortcut to `getWorkspaceRoot().getProject(name)`.
      Parameters:
        `name` - the name of the project
      Returns:
        the requested project (never `null`)

    - #### setUpProject

          protected final org.eclipse.core.resources.IProject setUpProject​(java.lang.String name)
                                                                    throws org.eclipse.core.runtime.CoreException,
                                                                           java.io.IOException

      Creates a new project in the workspace by copying its content from the OSGi-bundle of this test case. The content needs to reside in the folder `/workspace/`<project-name> inside the bundle.
      Parameters:
        `name` - the name of the project
      Returns:
        the created and opened project (never `null`)
      Throws:
        `org.eclipse.core.runtime.CoreException`
        `java.io.IOException`

    - #### setAutoBuilding

          protected final void setAutoBuilding​(boolean value)
                                        throws org.eclipse.core.runtime.CoreException

      Sets the property "Build Automatically" for the workspace.
      Parameters:
        `value` - boolean
      Throws:
        `org.eclipse.core.runtime.CoreException`

    - #### buildWorkspace

          protected final void buildWorkspace()
                                       throws org.eclipse.core.runtime.CoreException

      Builds the workspace, waiting for build completion.
      Throws:
        `org.eclipse.core.runtime.CoreException`

    - #### waitForBuildCompletion

          protected final void waitForBuildCompletion()

      Waits for build completion.

    - #### cleanUpWorkspace

          protected final void cleanUpWorkspace()
                                         throws org.eclipse.core.runtime.CoreException

      Deletes all resources in the workspace.
      Throws:
        `org.eclipse.core.runtime.CoreException`

    - #### suspendJobs

          protected final void suspendJobs()

      Suspends execution of all jobs.
      Since:
        1.7
      See Also:
        `resumeJobs()`

    - #### resumeJobs

          protected final void resumeJobs()

      Resumes execution of jobs.
      Since:
        1.7
      See Also:
        `suspendJobs()`