01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.ui.tests.search;
11:
12: import org.eclipse.core.resources.IResource;
13: import org.eclipse.jdt.core.IJavaElement;
14: import org.eclipse.jdt.internal.ui.search.JavaSearchQuery;
15: import org.eclipse.jdt.internal.ui.search.JavaSearchResult;
16: import org.eclipse.search.ui.text.IFileMatchAdapter;
17:
18: import junit.framework.Test;
19: import junit.framework.TestCase;
20: import junit.framework.TestSuite;
21:
22: /**
23: */
24: public class FileAdapterTest extends TestCase {
25:
26: public static Test allTests() {
27: return new JUnitSourceSetup(
28: new TestSuite(FileAdapterTest.class));
29: }
30:
31: public static Test suite() {
32: return allTests();
33: }
34:
35: public FileAdapterTest(String name) {
36: super (name);
37: }
38:
39: public void testGetFile() throws Exception {
40: JavaSearchQuery query = SearchTestHelper
41: .runTypeRefQuery("junit.framework.Test");
42: JavaSearchResult result = (JavaSearchResult) query
43: .getSearchResult();
44: IFileMatchAdapter adapter = result.getFileMatchAdapter();
45: Object[] elements = result.getElements();
46: for (int i = 0; i < elements.length; i++) {
47: IJavaElement je = (IJavaElement) elements[i];
48: IResource underlying = je.getUnderlyingResource();
49: if (underlying != null
50: && underlying.getName().endsWith(".java")) {
51: assertEquals(underlying, adapter.getFile(je));
52: } else {
53: assertNull(adapter.getFile(je));
54: }
55: }
56: }
57:
58: }
|