Hi,
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:
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
IPath newFilePath;
IPath originalFilePath;
File newFile;
File originalFile;
@Mock
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());
when(root.getLocation()).thenReturn(path);
newFile=new File(location, NEW_FILE);
originalFile=new File(location, ORIGINAL_FILE);
createOriginalFile();
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 java.io.File:
when(root.getFile(originalFilePath)).thenReturn(originalFile);
when(root.getFile(newFilePath)).thenReturn(newFile);
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!