Search in sources :

Example 1 with RevCommitUtil

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]);
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) URL(java.net.URL) Action(javax.swing.Action) GitTestBase(com.oxygenxml.git.service.GitTestBase) FileStatus(com.oxygenxml.git.service.entities.FileStatus) Answer(org.mockito.stubbing.Answer) GitAccess(com.oxygenxml.git.service.GitAccess) PrintWriter(java.io.PrintWriter) RepoGenerationScript(com.oxygenxml.git.utils.script.RepoGenerationScript) Iterator(java.util.Iterator) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Mockito(org.mockito.Mockito) List(java.util.List) MockedStatic(org.mockito.MockedStatic) GitOperationScheduler(com.oxygenxml.git.service.GitOperationScheduler) PluginWorkspaceProvider(ro.sync.exml.workspace.api.PluginWorkspaceProvider) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Git(org.eclipse.jgit.api.Git) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) RevCommitUtil(com.oxygenxml.git.service.RevCommitUtil) RevCommitUtil(com.oxygenxml.git.service.RevCommitUtil) PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) Action(javax.swing.Action) FileStatus(com.oxygenxml.git.service.entities.FileStatus) URL(java.net.URL) PluginWorkspaceProvider(ro.sync.exml.workspace.api.PluginWorkspaceProvider) File(java.io.File) Test(org.junit.Test)

Aggregations

GitAccess (com.oxygenxml.git.service.GitAccess)1 GitOperationScheduler (com.oxygenxml.git.service.GitOperationScheduler)1 GitTestBase (com.oxygenxml.git.service.GitTestBase)1 RevCommitUtil (com.oxygenxml.git.service.RevCommitUtil)1 FileStatus (com.oxygenxml.git.service.entities.FileStatus)1 GitChangeType (com.oxygenxml.git.service.entities.GitChangeType)1 RepoGenerationScript (com.oxygenxml.git.utils.script.RepoGenerationScript)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 Collectors (java.util.stream.Collectors)1 Action (javax.swing.Action)1 Git (org.eclipse.jgit.api.Git)1 Test (org.junit.Test)1