diff options
author | Markus Keller | 2016-02-15 12:25:21 +0000 |
---|---|---|
committer | Markus Keller | 2016-04-04 20:12:23 +0000 |
commit | bf92a4cb5abe8883e4e875a2e841279558dc657b (patch) | |
tree | e81b79d5c0de87b44e13120e7cb559122d7c2f34 /org.eclipse.search.tests | |
parent | 6820a987eaf2d9ee917064486a01eeff5339b906 (diff) | |
download | eclipse.platform.text-bf92a4cb5abe8883e4e875a2e841279558dc657b.tar.gz eclipse.platform.text-bf92a4cb5abe8883e4e875a2e841279558dc657b.tar.xz eclipse.platform.text-bf92a4cb5abe8883e4e875a2e841279558dc657b.zip |
Bug 487095: Move test bundles to JUnit 4Y20160407-1000I20160405-0800
- implement JUnitSourceSetup as ExternalResource
- clean up test suites
- update manifests
- use @Rule TestName to access test method names
FindReplaceDialogTest:
- fix test order
- fix wrong @Before tearDown()
Change-Id: Ibae60f592ea81dbbf2fab0db8daf64f92301dcdd
Diffstat (limited to 'org.eclipse.search.tests')
12 files changed, 126 insertions, 62 deletions
diff --git a/org.eclipse.search.tests/META-INF/MANIFEST.MF b/org.eclipse.search.tests/META-INF/MANIFEST.MF index 6169cd8bbbf..3af2eae617d 100644 --- a/org.eclipse.search.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.search.tests/META-INF/MANIFEST.MF @@ -15,7 +15,7 @@ Require-Bundle: org.eclipse.search;bundle-version="[3.5.100,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)", - org.junit;bundle-version="3.8.2", + org.junit;bundle-version="4.12.0", org.eclipse.ui.workbench.texteditor;bundle-version="[3.5.0,4.0.0)", org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.editors;bundle-version="[3.5.0,4.0.0)" diff --git a/org.eclipse.search.tests/src/org/eclipse/search/core/tests/AllSearchModelTests.java b/org.eclipse.search.tests/src/org/eclipse/search/core/tests/AllSearchModelTests.java index 05c483be330..d0269f652ca 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/core/tests/AllSearchModelTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/core/tests/AllSearchModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -14,12 +14,12 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import junit.framework.TestSuite; - @RunWith(Suite.class) -@SuiteClasses({QueryManagerTest.class, - TestSearchResult.class, - LineConversionTest.class}) -public class AllSearchModelTests extends TestSuite { - //intentionally left empty +@SuiteClasses({ + QueryManagerTest.class, + TestSearchResult.class, + LineConversionTest.class +}) +public class AllSearchModelTests { + // see @SuiteClasses } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/AllSearchTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/AllSearchTests.java index 8c4ae7ccacc..44070c9b8a8 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/AllSearchTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/AllSearchTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -18,9 +18,10 @@ import org.eclipse.search.core.tests.AllSearchModelTests; import org.eclipse.search.tests.filesearch.AllFileSearchTests; @RunWith(Suite.class) -@SuiteClasses({AllFileSearchTests.class, - AllSearchModelTests.class +@SuiteClasses({ + AllFileSearchTests.class, + AllSearchModelTests.class }) public class AllSearchTests { - //intentionally left blank + // see @SuiteClasses } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java index 3708c55ab0f..81c29d93ef7 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -10,46 +10,22 @@ *******************************************************************************/ package org.eclipse.search.tests.filesearch; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; - -import org.eclipse.search.tests.ResourceHelper; - @RunWith(Suite.class) @SuiteClasses({ - AnnotationManagerTest.class, - FileSearchTests.class, - LineAnnotationManagerTest.class, - PositionTrackerTest.class, - ResultUpdaterTest.class, - SearchResultPageTest.class, - SortingTest.class + AnnotationManagerTest.class, + FileSearchTests.class, + LineAnnotationManagerTest.class, + PositionTrackerTest.class, + ResultUpdaterTest.class, + SearchResultPageTest.class, + SortingTest.class }) public class AllFileSearchTests { - - public static final String STANDARD_PROJECT_NAME= "JUnitSource"; - - private static IProject fProject; - - @BeforeClass - public static void globalSetUp() throws Exception { - IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(STANDARD_PROJECT_NAME); - if (!project.exists()) { // allow nesting of JUnitSetups - fProject= ResourceHelper.createJUnitSourceProject(STANDARD_PROJECT_NAME); - } - } - - @AfterClass - public static void globalTearDown() throws Exception { - if (fProject != null) { // delete only by the setup who created the project - ResourceHelper.deleteProject(STANDARD_PROJECT_NAME); - fProject= null; - } - } + @ClassRule + public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup(); } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java index 05143ed8936..80881a32665 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -18,6 +18,7 @@ import java.util.Iterator; import org.junit.After; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; import org.eclipse.core.resources.IFile; @@ -52,6 +53,9 @@ public class AnnotationManagerTest { private AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup(); + @ClassRule + public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup(); + @Before public void setUp() { SearchTestPlugin.ensureWelcomePageClosed(); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java index 21bb28c3d89..2a8f6233011 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java @@ -128,8 +128,8 @@ public class FileCharSequenceTests { assertOutOfBound(desc + "access at length", actual, expected.length()); assertOutOfBound(desc + "access at -1", actual, -1); - - assertEquals(desc + " - length", actual.toString(), expected.toString()); + + Assert.assertEquals(desc + " - length", actual.toString(), expected.toString()); } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java index 06384d2cbc8..8a8502390ce 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -20,6 +20,7 @@ import java.util.regex.Pattern; import org.junit.After; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; import org.eclipse.core.runtime.CoreException; @@ -28,7 +29,6 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.ui.IWorkbenchPage; @@ -110,6 +110,9 @@ public class FileSearchTests { } + @ClassRule + public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup(); + private IProject fProject; @Before @@ -226,7 +229,7 @@ public class FileSearchTests { private void testWildCards3(TestResultCollector collector) throws Exception { - IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(AllFileSearchTests.STANDARD_PROJECT_NAME); + IProject project= fgJUnitSource.getStandardProject(); IFile openFile1= (IFile) project.findMember("junit/framework/TestCase.java"); IFile openFile2= (IFile) project.findMember("junit/extensions/ExceptionTestCase.java"); IFile openFile3= (IFile) project.findMember("junit/framework/Assert.java"); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/JUnitSourceSetup.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/JUnitSourceSetup.java new file mode 100644 index 00000000000..50849a88961 --- /dev/null +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/JUnitSourceSetup.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.search.tests.filesearch; + +import org.junit.rules.ExternalResource; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; + +import org.eclipse.search.tests.ResourceHelper; + +public class JUnitSourceSetup extends ExternalResource { + + public static final String STANDARD_PROJECT_NAME= "JUnitSource"; + + private IProject fProject= null; + private final String fProjectName; + + public IProject getStandardProject() { + return ResourcesPlugin.getWorkspace().getRoot().getProject(STANDARD_PROJECT_NAME); + } + + public JUnitSourceSetup() { + this(STANDARD_PROJECT_NAME); + } + + public JUnitSourceSetup(String projectName) { + fProjectName= projectName; + } + + @Override + public void before() throws Exception { + IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(fProjectName); + if (!project.exists()) { // allow nesting of JUnitSetups + fProject= ResourceHelper.createJUnitSourceProject(fProjectName); + } + } + + @Override + public void after() /*throws Exception (but JUnit4 API is stupid...)*/ { + if (fProject != null) { // delete only by the setup who created the project + try { + ResourceHelper.deleteProject(fProjectName); + } catch (CoreException e) { + throw new AssertionError(e); // workaround stupid JUnit4 API + } + fProject= null; + } + } + +} diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java index b8a11aaf3b6..eb18d53f23b 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -10,13 +10,15 @@ *******************************************************************************/ package org.eclipse.search.tests.filesearch; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Iterator; import org.junit.After; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; import org.eclipse.core.resources.IFile; @@ -49,6 +51,9 @@ public class LineAnnotationManagerTest { private LineBasedFileSearch fLineQuery; private AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup(); + @ClassRule + public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup(); + @Before public void setUp() throws Exception { EditorAnnotationManager.debugSetHighlighterType(EditorAnnotationManager.HIGHLIGHTER_ANNOTATION); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java index 80275ca5aa5..961316115ce 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -14,6 +14,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; import org.eclipse.core.resources.IFile; @@ -42,6 +43,9 @@ import org.eclipse.search2.internal.ui.InternalSearchUI; public class PositionTrackerTest { FileSearchQuery fQuery1; + @ClassRule + public static JUnitSourceSetup junitSource= new JUnitSourceSetup(); + @Before public void setUp() throws Exception { String[] fileNamePatterns= { "*.java" }; diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java index c7567462533..7d401f10ded 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -11,9 +11,11 @@ package org.eclipse.search.tests.filesearch; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Ignore; import org.junit.Test; @@ -42,6 +44,9 @@ import org.eclipse.search.ui.text.Match; public class SearchResultPageTest { FileSearchQuery fQuery1; + @ClassRule + public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup(); + @Before public void setUp() throws Exception { SearchTestPlugin.ensureWelcomePageClosed(); @@ -78,7 +83,7 @@ public class SearchResultPageTest { @Test - @Ignore + @Ignore // checkElementDisplay(..) misses cases where one line contains multiple matches public void testRemoveTreeMatches() throws Exception { NewSearchUI.runQueryInForeground(null, fQuery1); ISearchResultViewPart view= NewSearchUI.getSearchResultView(); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java index 402a97bef0c..2571535db8a 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * 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 @@ -10,12 +10,14 @@ *******************************************************************************/ package org.eclipse.search.tests.filesearch; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; import org.eclipse.search.internal.ui.text.FileSearchQuery; @@ -27,6 +29,9 @@ import org.eclipse.search.ui.text.Match; public class SortingTest { FileSearchQuery fQuery1; + @ClassRule + public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup(); + @Before public void setUp() throws Exception { String[] fileNamePatterns= { "*.java" }; |