1 /******************************************************************************* 2 * Copyright (c) 2008, 2018 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.pde.api.tools.builder.tests.tags; 15 16 import java.lang.reflect.InvocationTargetException; 17 import java.lang.reflect.Method; 18 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.jdt.core.tests.junit.extension.TestCase; 21 import org.eclipse.pde.api.tools.internal.problems.ApiProblemFactory; 22 import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; 23 import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; 24 25 import junit.framework.Test; 26 import junit.framework.TestSuite; 27 28 /** 29 * Tests unsupported javadoc tags on fields in classes, interfaces, enums and 30 * annotations 31 * 32 * @since 1.0 33 */ 34 public class InvalidFieldTagTests extends TagTest { 35 InvalidFieldTagTests(String name)36 public InvalidFieldTagTests(String name) { 37 super(name); 38 } 39 40 /** 41 * @return the tests for this class 42 */ suite()43 public static Test suite() { 44 TestSuite suite = new TestSuite(InvalidFieldTagTests.class.getName()); 45 collectTests(suite); 46 return suite; 47 } 48 49 @Override getDefaultProblemId()50 protected int getDefaultProblemId() { 51 return ApiProblemFactory.createProblemId(IApiProblem.CATEGORY_USAGE, IElementDescriptor.FIELD, IApiProblem.UNSUPPORTED_TAG_USE, IApiProblem.NO_FLAGS); 52 } 53 54 @Override getTestSourcePath()55 protected IPath getTestSourcePath() { 56 return super.getTestSourcePath().append("field"); //$NON-NLS-1$ 57 } 58 59 /** 60 * @return all of the child test classes of this class 61 */ getAllTestClasses()62 private static Class<?>[] getAllTestClasses() { 63 Class<?>[] classes = new Class[] { 64 InvalidClassFieldTagTests.class, 65 InvalidInterfaceFieldTagTests.class, 66 InvalidAnnotationFieldTagTests.class, 67 InvalidEnumFieldTagTests.class, 68 InvalidEnumConstantTagTests.class }; 69 return classes; 70 } 71 72 /** 73 * Collects tests from the getAllTestClasses() method into the given suite 74 * 75 * @param suite 76 */ collectTests(TestSuite suite)77 private static void collectTests(TestSuite suite) { 78 // Hack to load all classes before computing their suite of test cases 79 // this allow to reset test cases subsets while running all Builder 80 // tests... 81 Class<?>[] classes = getAllTestClasses(); 82 83 // Reset forgotten subsets of tests 84 TestCase.TESTS_PREFIX = null; 85 TestCase.TESTS_NAMES = null; 86 TestCase.TESTS_NUMBERS = null; 87 TestCase.TESTS_RANGE = null; 88 TestCase.RUN_ONLY_ID = null; 89 90 /* tests */ 91 for (int i = 0, length = classes.length; i < length; i++) { 92 Class<?> clazz = classes[i]; 93 Method suiteMethod; 94 try { 95 suiteMethod = clazz.getDeclaredMethod("suite"); //$NON-NLS-1$ 96 } catch (NoSuchMethodException e) { 97 e.printStackTrace(); 98 continue; 99 } 100 Object test; 101 try { 102 test = suiteMethod.invoke(null); 103 } catch (IllegalAccessException e) { 104 e.printStackTrace(); 105 continue; 106 } catch (InvocationTargetException e) { 107 e.printStackTrace(); 108 continue; 109 } 110 suite.addTest((Test) test); 111 } 112 } 113 } 114