Search in sources :

Example 1 with WorkingCopySelectionPanel

use of com.oxygenxml.git.view.staging.WorkingCopySelectionPanel in project oxygen-git-client-addon by oxygenxml.

the class WorkingCopySelectorTest method testClearHistory.

/**
 * <p><b>Description:</b> test the "Clear history..." action.</p>
 * <p><b>Bug ID:</b> EXM-44205</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception When failing.
 */
public void testClearHistory() throws Exception {
    JFrame frame = new JFrame();
    try {
        GitControllerBase mock = Mockito.mock(GitControllerBase.class);
        GitAccess instance = GitAccess.getInstance();
        Mockito.when(mock.getGitAccess()).thenReturn(instance);
        WorkingCopySelectionPanel wcPanel = new WorkingCopySelectionPanel(mock, true);
        frame.getContentPane().add(wcPanel);
        frame.pack();
        // Showing the WC panel also initializes the combo
        SwingUtilities.invokeAndWait(() -> frame.setVisible(true));
        sleep(150);
        JComboBox<String> workingCopyCombo = wcPanel.getWorkingCopyCombo();
        ComboBoxModel<String> model = workingCopyCombo.getModel();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < model.getSize(); i++) {
            sb.append(model.getElementAt(i)).append("\n");
        }
        assertEquals("D:/folder/WC1\n" + "D:/folder/WC2\n" + "D:/folder_doi/WC\n" + "CLEAR_HISTORY\n", sb.toString());
        SwingUtilities.invokeAndWait(() -> workingCopyCombo.setSelectedItem("CLEAR_HISTORY"));
        sleep(150);
        sb = new StringBuilder();
        for (int i = 0; i < model.getSize(); i++) {
            sb.append(model.getElementAt(i)).append("\n");
        }
        assertEquals("D:/folder/WC1\n", sb.toString());
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitAccess(com.oxygenxml.git.service.GitAccess) WorkingCopySelectionPanel(com.oxygenxml.git.view.staging.WorkingCopySelectionPanel) JFrame(javax.swing.JFrame)

Example 2 with WorkingCopySelectionPanel

use of com.oxygenxml.git.view.staging.WorkingCopySelectionPanel in project oxygen-git-client-addon by oxygenxml.

the class WorkingCopySelector2Test method testRemoveStaleEntries.

/**
 * <p><b>Description:</b> A non existing repository is removed from the combo.</p>
 * <p><b>Bug ID:</b> EXM-44820</p>
 *
 * @author alex_jitianu
 *
 * @throws Exception When failing.
 */
@Test
public void testRemoveStaleEntries() throws Exception {
    JFrame frame = new JFrame();
    try {
        WorkingCopySelectionPanel wcPanel = new WorkingCopySelectionPanel(new GitController(), true);
        frame.getContentPane().add(wcPanel);
        frame.pack();
        // Showing the WC panel also initializes the combo
        frame.setVisible(true);
        JComboBox<String> workingCopyCombo = wcPanel.getWorkingCopyCombo();
        ComboBoxModel<String> model = workingCopyCombo.getModel();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < model.getSize(); i++) {
            sb.append(model.getElementAt(i)).append("\n");
        }
        assertEquals(wcTree.getAbsolutePath() + "\n" + badWcTree.getAbsolutePath() + "\n" + "CLEAR_HISTORY\n" + "", sb.toString());
        // Select the bad WC.
        workingCopyCombo.setSelectedItem(badWcTree.getAbsolutePath());
        // Wait for the selection task to be completed by posting another task and waiting for its end.
        ScheduledFuture<?> schedule = GitOperationScheduler.getInstance().schedule(() -> {
        });
        schedule.get();
        sleep(300);
        sb = new StringBuilder();
        for (int i = 0; i < model.getSize(); i++) {
            sb.append(model.getElementAt(i)).append("\n");
        }
        assertEquals(wcTree.getAbsolutePath() + "\n" + "CLEAR_HISTORY\n" + "", sb.toString());
        assertEquals(wcTree.getAbsolutePath(), workingCopyCombo.getSelectedItem().toString());
        assertEquals("[" + badWcTree.getAbsolutePath() + "]", removedRepositories.toString());
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : WorkingCopySelectionPanel(com.oxygenxml.git.view.staging.WorkingCopySelectionPanel) JFrame(javax.swing.JFrame) GitController(com.oxygenxml.git.view.event.GitController) Test(org.junit.Test)

Aggregations

WorkingCopySelectionPanel (com.oxygenxml.git.view.staging.WorkingCopySelectionPanel)2 JFrame (javax.swing.JFrame)2 GitAccess (com.oxygenxml.git.service.GitAccess)1 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)1 GitController (com.oxygenxml.git.view.event.GitController)1 Test (org.junit.Test)1