use of com.oxygenxml.git.service.RevCommitUtil in project oxygen-git-client-addon by oxygenxml.
the class HistoryContextualActionsTest method testOpenWCMethod.
/**
* <p>
* <b>Description:</b> Tests the
* com.oxygenxml.git.view.history.HistoryViewContextualMenuPresenter.
* createOpenWorkingCopyFileAction(FileStatus, String, boolean) API.
* </p>
*
* <p>
* <b>Bug ID:</b> EXM-47571
* </p>
*
* @author Alex_Smarandache
*
* @throws Exception
*/
@Test
public void testOpenWCMethod() throws Exception {
gitAccess = GitAccess.getInstance();
gitAccess.createNewRepository(LOCAL_TEST_REPOSITORY);
File file = new File(LOCAL_TEST_REPOSITORY + "/test.xpr");
file.createNewFile();
gitAccess.add(new FileStatus(GitChangeType.ADD, file.getName()));
gitAccess.commit("file test added");
String[] urlOpenedFile = new String[1];
PluginWorkspace pluginWorkspace = Mockito.mock(PluginWorkspace.class);
Mockito.when(pluginWorkspace.open(Mockito.any(URL.class), Mockito.any(String.class), Mockito.any(String.class))).thenAnswer((Answer<Boolean>) invocation -> {
File file1 = new File(((URL) (invocation.getArgument(0))).getFile());
urlOpenedFile[0] = file1.getName();
return true;
});
try (MockedStatic<PluginWorkspaceProvider> provider = Mockito.mockStatic(PluginWorkspaceProvider.class);
MockedStatic<RevCommitUtil> revCommitUtil = Mockito.mockStatic(RevCommitUtil.class)) {
revCommitUtil.when(() -> RevCommitUtil.getNewPathInWorkingCopy((Git) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn(LOCAL_TEST_REPOSITORY + "/test.xpr");
provider.when(() -> PluginWorkspaceProvider.getPluginWorkspace()).thenReturn(pluginWorkspace);
assertNotNull(PluginWorkspaceProvider.getPluginWorkspace());
HistoryViewContextualMenuPresenter historyContextualMenu = new HistoryViewContextualMenuPresenter(null);
Action openWCVersionAction = historyContextualMenu.createOpenWorkingCopyFileAction(new FileStatus(GitChangeType.RENAME, LOCAL_TEST_REPOSITORY + "/test.xpr"), LOCAL_TEST_REPOSITORY + "/test.xpr", false);
openWCVersionAction.actionPerformed(null);
}
assertEquals("test.xpr", urlOpenedFile[0]);
}
Aggregations