| /******************************************************************************* |
| * Copyright (c) 2013 Georgi Konstantinov. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Georgi Konstantinov - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.wst.sse.sieditor.search.ui.tree; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.jface.resource.ImageRegistry; |
| import org.eclipse.wst.sse.sieditor.ui.Activator; |
| import org.junit.Assert; |
| import org.junit.BeforeClass; |
| import org.junit.Test; |
| import org.mockito.Mockito; |
| |
| @SuppressWarnings("nls") |
| public class FileNodeTest { |
| |
| private static final String PATH = "path"; |
| private static FileNode fileNode; |
| private static RootTreeNode rootTreeNode; |
| private static IFile fileMock; |
| |
| @BeforeClass |
| public static void setUp() { |
| fileMock = Mockito.mock(IFile.class); |
| IPath pathMock = Mockito.mock(IPath.class); |
| Mockito.when(pathMock.toString()).thenReturn(PATH); |
| Mockito.when(fileMock.getFullPath()).thenReturn(pathMock); |
| rootTreeNode = new RootTreeNode(); |
| fileNode = new FileNode(fileMock, rootTreeNode, true); |
| } |
| |
| @Test |
| public void testGetParent() { |
| Assert.assertEquals(rootTreeNode, fileNode.getParent()); |
| } |
| |
| @Test |
| public void testGetFile() { |
| Assert.assertEquals(fileMock, fileNode.getFile()); |
| } |
| |
| @Test |
| public void testGetText() { |
| Assert.assertEquals(PATH, fileNode.getDisplayName()); |
| Assert.assertEquals(PATH, fileNode.getTreeDisplayText()); |
| Assert.assertEquals(PATH, fileNode.getTypeDisplayText()); |
| } |
| |
| @Test |
| public void testGetImage() { |
| ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry(); |
| FileNode xsdFileNode = new FileNode(fileMock, rootTreeNode, true); |
| Assert.assertTrue(xsdFileNode.isXsdFile()); |
| Assert.assertEquals(imageRegistry.get(Activator.NODE_XSD_FILE), xsdFileNode.getImage()); |
| |
| FileNode wsdlFileNode = new FileNode(fileMock, rootTreeNode, false); |
| Assert.assertFalse(wsdlFileNode.isXsdFile()); |
| Assert.assertEquals(imageRegistry.get(Activator.NODE_WSDL_FILE), wsdlFileNode.getImage()); |
| |
| } |
| } |