Skip to content

Commit

Permalink
Move plugin constants from ResourceTest to utility class eclipse-plat…
Browse files Browse the repository at this point in the history
…form#903

This change moves the constants and related methods referring to
extensions of resources test plugin from the ResourceTest class to a
separate utility class. It prepares for removing the JUnit 3 inheritance
hierarchy of ResourceTest to migrate to JUnit 4.

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Nov 30, 2023
1 parent 76ee2ef commit 1d6e4e6
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;


import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SNOW;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_WATER;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
import static org.eclipse.core.tests.resources.TestUtil.waitForCondition;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.filesystem.wrapper;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;

import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.filesystem.EFS;
Expand All @@ -23,7 +25,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.tests.harness.CoreTest;
import org.eclipse.core.tests.resources.ResourceTest;

/**
* A simple file system implementation that acts as a wrapper around the
Expand Down Expand Up @@ -92,7 +93,7 @@ public IFileStore getStore(URI uri) {
try {
baseStore = EFS.getStore(getBasicURI(uri));
} catch (CoreException e) {
CoreTest.log(ResourceTest.PI_RESOURCES_TESTS, e);
CoreTest.log(PI_RESOURCES_TESTS, e);
return NULL_ROOT;
}
return WrapperFileStore.newInstance(customFS, baseStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.properties;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
import static org.junit.Assert.assertNotEquals;

import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*******************************************************************************/
package org.eclipse.core.tests.resources;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_EARTH;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_MISSING;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SIMPLE;
import static org.junit.Assert.assertThrows;

import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
******************************************************************************/
package org.eclipse.core.tests.resources;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SIMPLE;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Dictionary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*******************************************************************************/
package org.eclipse.core.tests.resources;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
import static org.junit.Assert.assertThrows;

import java.io.DataInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
*******************************************************************************/
package org.eclipse.core.tests.resources;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_CYCLE1;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_CYCLE2;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_CYCLE3;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_EARTH;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_INVALID;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_MUD;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SIMPLE;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SNOW;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_WATER;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.SET_OTHER;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.SET_STATE;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.getInvalidNatureSets;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.getValidNatureSets;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
******************************************************************************/
package org.eclipse.core.tests.resources;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_EARTH;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_MISSING;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SIMPLE;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;

import java.io.File;
import java.nio.file.Files;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*******************************************************************************/
package org.eclipse.core.tests.resources;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SIMPLE;
import static org.junit.Assert.assertThrows;

import java.io.BufferedInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
*******************************************************************************/
package org.eclipse.core.tests.resources;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_127562;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_EARTH;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_MISSING;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SIMPLE;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SNOW;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_WATER;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.getInvalidNatureSets;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.getValidNatureSets;
import static org.junit.Assert.assertThrows;

import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*******************************************************************************/
package org.eclipse.core.tests.resources;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -73,40 +74,6 @@
* Superclass for tests that use the Eclipse Platform workspace.
*/
public abstract class ResourceTest extends CoreTest {
//nature that installs and runs a builder (regression test for bug 29116)
protected static final String NATURE_29116 = "org.eclipse.core.tests.resources.nature29116";

//cycle1 requires: cycle2
protected static final String NATURE_CYCLE1 = "org.eclipse.core.tests.resources.cycle1";
//cycle2 requires: cycle3
protected static final String NATURE_CYCLE2 = "org.eclipse.core.tests.resources.cycle2";

//constants for nature ids

//cycle3 requires: cycle1
protected static final String NATURE_CYCLE3 = "org.eclipse.core.tests.resources.cycle3";
//earthNature, one-of: stateSet
protected static final String NATURE_EARTH = "org.eclipse.core.tests.resources.earthNature";
//invalidNature
protected static final String NATURE_INVALID = "org.eclipse.core.tests.resources.invalidNature";
//missing nature
protected static final String NATURE_MISSING = "no.such.nature.Missing";
//missing pre-req nature
protected static final String NATURE_MISSING_PREREQ = "org.eclipse.core.tests.resources.missingPrerequisiteNature";
//mudNature, requires: waterNature, earthNature, one-of: otherSet
protected static final String NATURE_MUD = "org.eclipse.core.tests.resources.mudNature";
//simpleNature
protected static final String NATURE_SIMPLE = "org.eclipse.core.tests.resources.simpleNature";
//nature for regression tests of bug 127562
protected static final String NATURE_127562 = "org.eclipse.core.tests.resources.bug127562Nature";
//snowNature, requires: waterNature, one-of: otherSet
protected static final String NATURE_SNOW = "org.eclipse.core.tests.resources.snowNature";
//waterNature, one-of: stateSet
protected static final String NATURE_WATER = "org.eclipse.core.tests.resources.waterNature";
public static final String PI_RESOURCES_TESTS = "org.eclipse.core.tests.resources"; //$NON-NLS-1$
protected static final String SET_OTHER = "org.eclipse.core.tests.resources.otherSet";
//constants for nature sets
protected static final String SET_STATE = "org.eclipse.core.tests.resources.stateSet";

/**
* For retrieving the test name when executing test class with JUnit 4.
Expand Down Expand Up @@ -826,25 +793,6 @@ boolean resourceExists() {
return checkIfResourceExistsJob.resourceExists();
}

/**
* Returns invalid sets of natures
*/
protected String[][] getInvalidNatureSets() {
return new String[][] {{NATURE_SNOW}, //missing water pre-req
{NATURE_WATER, NATURE_EARTH}, //duplicates from state-set
{NATURE_WATER, NATURE_MUD}, //missing earth pre-req
{NATURE_WATER, NATURE_EARTH, NATURE_MUD}, //duplicates from state-set
{NATURE_SIMPLE, NATURE_SNOW, NATURE_WATER, NATURE_MUD}, //duplicates from other-set, missing pre-req
{NATURE_MISSING}, //doesn't exist
{NATURE_SIMPLE, NATURE_MISSING}, //missing doesn't exist
{NATURE_MISSING_PREREQ}, //requires nature that doesn't exist
{NATURE_SIMPLE, NATURE_MISSING_PREREQ}, //requires nature that doesn't exist
{NATURE_CYCLE1}, //missing pre-req
{NATURE_CYCLE2, NATURE_CYCLE3}, //missing pre-req
{NATURE_CYCLE1, NATURE_SIMPLE, NATURE_CYCLE2, NATURE_CYCLE3}, //cycle
};
}

protected String getLineSeparatorFromFile(IFile file) {
if (file.exists()) {
InputStream input = null;
Expand Down Expand Up @@ -911,13 +859,6 @@ public String getUniqueString() {
return new UniversalUniqueIdentifier().toString();
}

/**
* Returns valid sets of natures
*/
protected String[][] getValidNatureSets() {
return new String[][] {{}, {NATURE_SIMPLE}, {NATURE_SNOW, NATURE_WATER}, {NATURE_EARTH}, {NATURE_WATER, NATURE_SIMPLE, NATURE_SNOW},};
}

/**
* Checks whether the local file system supports accessing and modifying
* the given attribute.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************************************************************
* Copyright (c) 2023 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*******************************************************************************/
package org.eclipse.core.tests.resources;

/**
* A utility class representing information about the extensions defined in this
* test project.
*/
public final class ResourceTestPluginConstants {
public static final String PI_RESOURCES_TESTS = "org.eclipse.core.tests.resources"; //$NON-NLS-1$

// nature that installs and runs a builder (regression test for bug 29116)
public static final String NATURE_29116 = "org.eclipse.core.tests.resources.nature29116";
// cycle1 requires: cycle2
public static final String NATURE_CYCLE1 = "org.eclipse.core.tests.resources.cycle1";
// cycle2 requires: cycle3
public static final String NATURE_CYCLE2 = "org.eclipse.core.tests.resources.cycle2";
// cycle3 requires: cycle1
public static final String NATURE_CYCLE3 = "org.eclipse.core.tests.resources.cycle3";
// earthNature, one-of: stateSet
public static final String NATURE_EARTH = "org.eclipse.core.tests.resources.earthNature";
// invalidNature
public static final String NATURE_INVALID = "org.eclipse.core.tests.resources.invalidNature";
// missing nature
public static final String NATURE_MISSING = "no.such.nature.Missing";
// missing pre-req nature
public static final String NATURE_MISSING_PREREQ = "org.eclipse.core.tests.resources.missingPrerequisiteNature";
// mudNature, requires: waterNature, earthNature, one-of: otherSet
public static final String NATURE_MUD = "org.eclipse.core.tests.resources.mudNature";
// simpleNature
public static final String NATURE_SIMPLE = "org.eclipse.core.tests.resources.simpleNature";
// nature for regression tests of bug 127562
public static final String NATURE_127562 = "org.eclipse.core.tests.resources.bug127562Nature";
// snowNature, requires: waterNature, one-of: otherSet
public static final String NATURE_SNOW = "org.eclipse.core.tests.resources.snowNature";
// waterNature, one-of: stateSet
public static final String NATURE_WATER = "org.eclipse.core.tests.resources.waterNature";
public static final String SET_OTHER = "org.eclipse.core.tests.resources.otherSet";
// constants for nature sets
public static final String SET_STATE = "org.eclipse.core.tests.resources.stateSet";

private ResourceTestPluginConstants() {
}

/**
* Returns valid sets of natures
*/
public static String[][] getValidNatureSets() {
return new String[][] { {}, { NATURE_SIMPLE }, { NATURE_SNOW, NATURE_WATER }, { NATURE_EARTH },
{ NATURE_WATER, NATURE_SIMPLE, NATURE_SNOW }, };
}

/**
* Returns invalid sets of natures
*/
public static String[][] getInvalidNatureSets() {
return new String[][] { { NATURE_SNOW }, // missing water pre-req
{ NATURE_WATER, NATURE_EARTH }, // duplicates from state-set
{ NATURE_WATER, NATURE_MUD }, // missing earth pre-req
{ NATURE_WATER, NATURE_EARTH, NATURE_MUD }, // duplicates from state-set
{ NATURE_SIMPLE, NATURE_SNOW, NATURE_WATER, NATURE_MUD }, // duplicates from other-set, missing pre-req
{ NATURE_MISSING }, // doesn't exist
{ NATURE_SIMPLE, NATURE_MISSING }, // missing doesn't exist
{ NATURE_MISSING_PREREQ }, // requires nature that doesn't exist
{ NATURE_SIMPLE, NATURE_MISSING_PREREQ }, // requires nature that doesn't exist
{ NATURE_CYCLE1 }, // missing pre-req
{ NATURE_CYCLE2, NATURE_CYCLE3 }, // missing pre-req
{ NATURE_CYCLE1, NATURE_SIMPLE, NATURE_CYCLE2, NATURE_CYCLE3 }, // cycle
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.perf;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.regression;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_29116;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.regression;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.regression;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;

import java.util.concurrent.Semaphore;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.session;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.session;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;

import junit.framework.Test;
import org.eclipse.core.internal.resources.ContentDescriptionManager;
import org.eclipse.core.internal.resources.Workspace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.session;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SNOW;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_WATER;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import junit.framework.Test;
Expand Down

0 comments on commit 1d6e4e6

Please sign in to comment.