01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 BEA Systems, Inc.
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: * jgarms@bea.com - initial API and implementation
10: *
11: *******************************************************************************/package org.eclipse.jdt.apt.tests;
12:
13: import junit.framework.Test;
14: import junit.framework.TestSuite;
15:
16: import org.eclipse.core.resources.IFolder;
17: import org.eclipse.core.resources.IProject;
18: import org.eclipse.core.runtime.IPath;
19: import org.eclipse.jdt.apt.tests.annotations.mirrortest.CodeExample;
20: import org.eclipse.jdt.apt.tests.annotations.mirrortest.MirrorTestAnnotationProcessor;
21: import org.eclipse.jdt.core.tests.builder.BuilderTests;
22: import org.eclipse.jdt.core.tests.util.Util;
23:
24: /**
25: * Test that processors do not get invoked on pre-1.5 projects
26: */
27: public class JavaVersionTests extends BuilderTests {
28:
29: public JavaVersionTests(final String name) {
30: super (name);
31: }
32:
33: public static Test suite() {
34: return new TestSuite(JavaVersionTests.class);
35: }
36:
37: public void setUp() throws Exception {
38: super .setUp();
39:
40: // project will be deleted by super-class's tearDown() method
41: IPath projectPath = env.addProject(getProjectName(), "1.4"); //$NON-NLS-1$
42: env.addExternalJars(projectPath, Util.getJavaClassLibs());
43: fullBuild(projectPath);
44:
45: // remove old package fragment root so that names don't collide
46: env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
47:
48: env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
49: env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
50:
51: TestUtil.createAndAddAnnotationJar(env
52: .getJavaProject(projectPath));
53: }
54:
55: public static String getProjectName() {
56: return JavaVersionTests.class.getName() + "Project"; //$NON-NLS-1$
57: }
58:
59: public IPath getSourcePath() {
60: IProject project = env.getProject(getProjectName());
61: IFolder srcFolder = project.getFolder("src"); //$NON-NLS-1$
62: IPath srcRoot = srcFolder.getFullPath();
63: return srcRoot;
64: }
65:
66: /**
67: * Runs the MirrorTestAnnotationProcessor, which contains
68: * the actual tests
69: */
70: public void testMirror() throws Exception {
71: MirrorTestAnnotationProcessor._processRun = false;
72:
73: IProject project = env.getProject(getProjectName());
74: IPath srcRoot = getSourcePath();
75:
76: String code = CodeExample.CODE;
77:
78: env.addClass(srcRoot, CodeExample.CODE_PACKAGE,
79: CodeExample.CODE_CLASS_NAME, code);
80:
81: fullBuild(project.getFullPath());
82:
83: assertFalse(
84: "Processor was run", MirrorTestAnnotationProcessor._processRun); //$NON-NLS-1$
85: }
86:
87: }
|