Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » [Mockito testing] Problem Setting a mocked IWorkspaceRoot to return desired files(Setting a mocked IWorkspaceRoot to return desired's)
[Mockito testing] Problem Setting a mocked IWorkspaceRoot to return desired files [message #1156365] Sat, 26 October 2013 13:56
Stefan Prisca is currently offline Stefan PriscaFriend
Messages: 11
Registered: July 2013
Junior Member

I am trying to write a unit test for the save-as action of an editor using Mockito.

I created a temporary folder, a Mock WorkspaceRoot, and there are two files with coresponding IPaths:
    public TemporaryFolder tempFolder = new TemporaryFolder();
    IPath newFilePath;
    IPath originalFilePath;
    File newFile;
    File originalFile;
    private WorkspaceRoot root;

Afterwards I set the root location to the tempFolder, created the files and set the paths accordingly:
        File location = tempFolder.newFolder("someNewFolder");
        IPath path= new Path(location.getAbsolutePath());
        newFile=new File(location, NEW_FILE);
        originalFile=new File(location, ORIGINAL_FILE);
        newFilePath=new Path(newFile.getAbsolutePath()).makeRelativeTo(root.getLocation());
        originalFilePath=new Path(originalFile.getAbsolutePath()).makeRelativeTo(root.getLocation());

The plan is to call the
performSaveAsAction(IWorkspaceRoot root, IPath newPath, IPath originalPath)
with the mocked workspace root and the path for the files that I created, like this:
performSaveAsAction(root, newFilePath, originalFilePath)

This should create a new file using the newFilePath with the contents of the file found at originalFilePath.
But I cannot set the root to return either of the files, as the getFile() method needs to return an IFile and both files are


Any ideas on how to set the root to return the files I created, or how I could create IFiles in the desired directory, without setting up a whole project?

Thank you!
Previous Topic:Exporting Ant scripts
Next Topic:Re: Server
Goto Forum:

Current Time: Fri Jun 22 17:29:54 GMT 2018

Powered by FUDForum. Page generated in 0.01798 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top