| /******************************************************************************* |
| * Copyright (c) 2008, 2014 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.pde.api.tools.builder.tests.tags; |
| |
| import java.lang.reflect.InvocationTargetException; |
| import java.lang.reflect.Method; |
| import java.util.ArrayList; |
| |
| import junit.framework.Test; |
| import junit.framework.TestSuite; |
| |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.jdt.core.tests.junit.extension.TestCase; |
| |
| /** |
| * Tests valid javadoc tags on methods in classes, interfaces, enums and |
| * annotations |
| * |
| * @since 1.0 |
| */ |
| public class ValidMethodTagTests extends InvalidMethodTagTests { |
| |
| /** |
| * Constructor |
| * |
| * @param name |
| */ |
| public ValidMethodTagTests(String name) { |
| super(name); |
| } |
| |
| /** |
| * @return the tests for this class |
| */ |
| public static Test suite() { |
| TestSuite suite = new TestSuite(ValidMethodTagTests.class.getName()); |
| collectTests(suite); |
| return suite; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see |
| * org.eclipse.pde.api.tools.builder.tests.ApiBuilderTests#getTestSourcePath |
| * () |
| */ |
| @Override |
| protected IPath getTestSourcePath() { |
| return super.getTestSourcePath().append("valid"); //$NON-NLS-1$ |
| } |
| |
| /** |
| * @return all of the child test classes of this class |
| */ |
| private static Class<?>[] getAllTestClasses() { |
| ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); |
| classes.add(ValidClassMethodTagTests.class); |
| classes.add(ValidInterfaceMethodTagTests.class); |
| classes.add(ValidEnumMethodTagTests.class); |
| return classes.toArray(new Class[classes.size()]); |
| } |
| |
| /** |
| * Collects tests from the getAllTestClasses() method into the given suite |
| * |
| * @param suite |
| */ |
| private static void collectTests(TestSuite suite) { |
| // Hack to load all classes before computing their suite of test cases |
| // this allow to reset test cases subsets while running all Builder |
| // tests... |
| Class<?>[] classes = getAllTestClasses(); |
| |
| // Reset forgotten subsets of tests |
| TestCase.TESTS_PREFIX = null; |
| TestCase.TESTS_NAMES = null; |
| TestCase.TESTS_NUMBERS = null; |
| TestCase.TESTS_RANGE = null; |
| TestCase.RUN_ONLY_ID = null; |
| |
| /* tests */ |
| for (int i = 0, length = classes.length; i < length; i++) { |
| Class<?> clazz = classes[i]; |
| Method suiteMethod; |
| try { |
| suiteMethod = clazz.getDeclaredMethod("suite", new Class[0]); //$NON-NLS-1$ |
| } catch (NoSuchMethodException e) { |
| e.printStackTrace(); |
| continue; |
| } |
| Object test; |
| try { |
| test = suiteMethod.invoke(null, new Object[0]); |
| } catch (IllegalAccessException e) { |
| e.printStackTrace(); |
| continue; |
| } catch (InvocationTargetException e) { |
| e.printStackTrace(); |
| continue; |
| } |
| suite.addTest((Test) test); |
| } |
| } |
| } |