public static SearchResultGroup[] createFakeSearchResult(SearchResultGroup[] returnValue, Object/* * org.eclipse.jdt.internal.corext.refactoring.rename. * RenameFieldProcessor */ processor) throws Exception { if (returnValue == null || returnValue.length == 0) { // if no matches were found, check if Data annotation is present on the class Field declaredField = processor.getClass().getDeclaredField("fField"); if (declaredField != null) { declaredField.setAccessible(true); SourceField fField = (SourceField) declaredField.get(processor); IAnnotation dataAnnotation = fField.getDeclaringType().getAnnotation("Data"); if (dataAnnotation != null) { // add fake item, to make refactoring checks pass return new SearchResultGroup[] {new SearchResultGroup(null, new SearchMatch[1])}; } } } return returnValue; }
/** * @param element the element * @return <code>true</code> if the element is a test class annotated with * <code>@RunWith(JUnitPlatform.class)</code> */ public static boolean isRunWithJUnitPlatform(IJavaElement element) { if (element instanceof ICompilationUnit) { element= ((ICompilationUnit) element).findPrimaryType(); } if (element instanceof IType) { IType type= (IType) element; try { IAnnotation runWithAnnotation= type.getAnnotation("RunWith"); //$NON-NLS-1$ if (!runWithAnnotation.exists()) { runWithAnnotation= type.getAnnotation("org.junit.runner.RunWith"); //$NON-NLS-1$ } if (runWithAnnotation.exists()) { IMemberValuePair[] memberValuePairs= runWithAnnotation.getMemberValuePairs(); for (IMemberValuePair memberValuePair : memberValuePairs) { if (memberValuePair.getMemberName().equals("value") && memberValuePair.getValue().equals("JUnitPlatform")) { //$NON-NLS-1$ //$NON-NLS-2$ return true; } } } } catch (JavaModelException e) { // ignore } } return false; }
public static boolean isAccessibleClass(IType type, String testKindId) throws JavaModelException { int flags= type.getFlags(); if (Flags.isInterface(flags)) { return false; } IJavaElement parent= type.getParent(); while (true) { if (parent instanceof ICompilationUnit || parent instanceof IClassFile) { return true; } if (!(parent instanceof IType)) { return false; } if (TestKindRegistry.JUNIT5_TEST_KIND_ID.equals(testKindId)) { // A nested/inner class need not be public in JUnit 5. if (Flags.isPrivate(flags)) { return false; } // If the inner class is non-static, it must be annotated with @Nested. if (!Flags.isStatic(flags) && !type.getAnnotation("Nested").exists()) { //$NON-NLS-1$ return false; } } else if (!Flags.isStatic(flags) || !Flags.isPublic(flags)) { return false; } flags= ((IType) parent).getFlags(); parent= parent.getParent(); } }