Archive

Archive for January, 2011

Help! I Programmatically Created a Resource in my Project, but My Code Doesn’t Find It!

January 1, 2011 5 comments

Let’s say that you wanted to test the existence of a file you programmatically created in your project. While there are a lot of situations where you might create an IResource on the fly, creating a file for use in a test is not a bad example.

The test code could look like this (TestUtilities is a convenience class that does things for me):

...
import org.junit.Assert;
...
    @Test
    public void testFileExistsTrue() throws IOException, CoreException {
        _project = TestUtilities.createProject("x"); //$NON-NLS-1$
        TestUtilities.createTemplateFileInProjectAt(_project, CustomSchemaSupport.SCHEMA_FOLDER_NAME, CustomSchemaSupport.FILENAME);

        boolean actual = _customSchemaSupport.fileExists(_project);

        try {
            Assert.assertTrue(actual);
        } finally {
            // always do this before returning
            _project.delete(true, null);
        }
    }

Read more…