Search in sources :

Example 1 with CorePlugin

use of org.talend.dataprofiler.core.CorePlugin in project tdq-studio-se by Talend.

the class UnitTestBuildHelper method mockCorePlugin.

public static CorePlugin mockCorePlugin() {
    CorePlugin corePlugin = mock(CorePlugin.class);
    PowerMockito.mockStatic(CorePlugin.class);
    when(CorePlugin.getDefault()).thenReturn(corePlugin);
    return corePlugin;
}
Also used : CorePlugin(org.talend.dataprofiler.core.CorePlugin)

Example 2 with CorePlugin

use of org.talend.dataprofiler.core.CorePlugin in project tdq-studio-se by Talend.

the class WorkspaceResourceHelperTest method testSourceFileHasBeenOpened.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.helper.WorkspaceResourceHelper#sourceFileHasBeenOpened(org.talend.repository.model.IRepositoryNode)}
 * .
 */
@Test
public void testSourceFileHasBeenOpened() {
    SourceFileRepNode fileNode = mock(SourceFileRepNode.class);
    CorePlugin cpMock = mock(CorePlugin.class);
    PowerMockito.mockStatic(CorePlugin.class);
    when(CorePlugin.getDefault()).thenReturn(cpMock);
    IWorkbench workbenchMock = mock(IWorkbench.class);
    when(cpMock.getWorkbench()).thenReturn(workbenchMock);
    IWorkbenchWindow workbenchWindowMock = mock(IWorkbenchWindow.class);
    when(workbenchMock.getActiveWorkbenchWindow()).thenReturn(workbenchWindowMock);
    IWorkbenchPage workbenchPageMock = mock(IWorkbenchPage.class);
    when(workbenchWindowMock.getActivePage()).thenReturn(workbenchPageMock);
    IEditorReference editorRefMock = mock(IEditorReference.class);
    IEditorReference[] editorRefMocks = new IEditorReference[] { editorRefMock };
    when(workbenchPageMock.getEditorReferences()).thenReturn(editorRefMocks);
    FileEditorInput fileEditorInputMock = mock(FileEditorInput.class);
    try {
        when(editorRefMock.getEditorInput()).thenReturn(fileEditorInputMock);
    } catch (PartInitException e) {
        fail(e.getMessage());
    }
    IFile nodeFileMock = mock(IFile.class);
    // $NON-NLS-1$
    stub(method(RepositoryNodeHelper.class, "getIFile", SourceFileRepNode.class)).toReturn(nodeFileMock);
    IPath nodeFilePathMock = mock(IPath.class);
    when(nodeFileMock.getFullPath()).thenReturn(nodeFilePathMock);
    // $NON-NLS-1$
    String path = "/abc";
    when(nodeFilePathMock.toString()).thenReturn(path);
    IFile inputFileMock = mock(IFile.class);
    when(fileEditorInputMock.getFile()).thenReturn(inputFileMock);
    IPath inputFilePathMock = mock(IPath.class);
    when(inputFileMock.getFullPath()).thenReturn(inputFilePathMock);
    when(inputFilePathMock.toString()).thenReturn(path);
    assertTrue(WorkspaceResourceHelper.sourceFileHasBeenOpened(fileNode));
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) CorePlugin(org.talend.dataprofiler.core.CorePlugin) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

CorePlugin (org.talend.dataprofiler.core.CorePlugin)2 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PartInitException (org.eclipse.ui.PartInitException)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 SourceFileRepNode (org.talend.dq.nodes.SourceFileRepNode)1