/** @return were javadoc params used */ public static void collectAnnotationValues( final Map<String, Collection<String>> results, PsiMethod[] psiMethods, PsiClass... classes) { final Set<String> test = new HashSet<>(1); test.add(TEST_ANNOTATION_FQN); ContainerUtil.addAll(test, CONFIG_ANNOTATIONS_FQN); if (psiMethods != null) { for (final PsiMethod psiMethod : psiMethods) { ApplicationManager.getApplication() .runReadAction( () -> appendAnnotationAttributeValues( results, AnnotationUtil.findAnnotation(psiMethod, test), psiMethod)); } } else { for (final PsiClass psiClass : classes) { ApplicationManager.getApplication() .runReadAction( () -> { if (psiClass != null && hasTest(psiClass)) { appendAnnotationAttributeValues( results, AnnotationUtil.findAnnotation(psiClass, test), psiClass); PsiMethod[] methods = psiClass.getMethods(); for (PsiMethod method : methods) { if (method != null) { appendAnnotationAttributeValues( results, AnnotationUtil.findAnnotation(method, test), method); } } } }); } } }
/** * Filter the specified collection of classes to return only ones that contain any of the * specified values in the specified annotation parameter. For example, this method can be used to * return all classes that contain all tesng annotations that are in the groups 'foo' or 'bar'. */ public static Map<PsiClass, Collection<PsiMethod>> filterAnnotations( String parameter, Set<String> values, Collection<PsiClass> classes) { Map<PsiClass, Collection<PsiMethod>> results = new HashMap<>(); Set<String> test = new HashSet<>(1); test.add(TEST_ANNOTATION_FQN); ContainerUtil.addAll(test, CONFIG_ANNOTATIONS_FQN); for (PsiClass psiClass : classes) { if (isBrokenPsiClass(psiClass)) continue; PsiAnnotation annotation; try { annotation = AnnotationUtil.findAnnotation(psiClass, test); } catch (Exception e) { LOGGER.error( "Exception trying to findAnnotation on " + psiClass.getClass().getName() + ".\n\n" + e.getMessage()); annotation = null; } if (annotation != null) { if (isAnnotatedWithParameter(annotation, parameter, values)) { results.put(psiClass, new LinkedHashSet<>()); } } else { Collection<String> matches = extractAnnotationValuesFromJavaDoc(getTextJavaDoc(psiClass), parameter); for (String s : matches) { if (values.contains(s)) { results.put(psiClass, new LinkedHashSet<>()); break; } } } // we already have the class, no need to look through its methods PsiMethod[] methods = psiClass.getMethods(); for (PsiMethod method : methods) { if (method != null) { annotation = AnnotationUtil.findAnnotation(method, test); if (annotation != null) { if (isAnnotatedWithParameter(annotation, parameter, values)) { if (results.get(psiClass) == null) results.put(psiClass, new LinkedHashSet<>()); results.get(psiClass).add(method); } } else { Collection<String> matches = extractAnnotationValuesFromJavaDoc(getTextJavaDoc(psiClass), parameter); for (String s : matches) { if (values.contains(s)) { results.get(psiClass).add(method); } } } } } } return results; }
@AfterClass public void confirmMultipleThreads() { Assert.assertTrue( _threads.size() > 1, "More than one thread should have been used for running the tests - " + _threads.size() + " was used"); }
@Test public void testLoadData() { final Set<TestBean> theLoadedBeans = new HashSet<TestBean>(); this.myDataLoader.loadData( new DataConsumer() { public void consume(Map<String, Object> aRecord) { theLoadedBeans.add( new TestBean( (String) aRecord.get(FIRST_NAME_PROP_NAME), (String) aRecord.get(LAST_NAME_PROP_NAME), (String) aRecord.get(FAVORITE_COLOR))); } }); assertEquals(theLoadedBeans.size(), this.myExpectedBeans.size()); assertTrue( this.myExpectedBeans.containsAll(theLoadedBeans), format("%1$s does not match %2$s", theLoadedBeans, this.myExpectedBeans)); }
public static boolean isAnnotatedWithParameter( PsiAnnotation annotation, String parameter, Set<String> values) { final PsiAnnotationMemberValue attributeValue = annotation.findDeclaredAttributeValue(parameter); if (attributeValue != null) { Collection<String> matches = extractValuesFromParameter(attributeValue); for (String s : matches) { if (values.contains(s)) { return true; } } } return false; }
public FunctionalTest() throws IOException { Vector v = new Vector(); for (Enumeration e = v.elements(); e.hasMoreElements(); ) {} IOException e = new IOException(); // this is to test excluding literals String buz = "text/plain"; // this is to test array handling ArrayList[] foo = new ArrayList[0]; ArrayList bar = new ArrayList(); bar.add(HashSet.class); bar.add(Integer.class); File[] files = (File[]) bar.toArray(new File[0]); // this is to test imports of inner classes HashMap biv = new HashMap(); Set set = biv.entrySet(); Iterator iter = set.iterator(); bar.add((Entry) iter.next()); // this is to test inclusion of classes from java.lang.reflect Modifier m = new Modifier(); // This next one can't be picked up by importscrubber because the compiler inlines it // System.out.println("A JOptionPane thingy " + JOptionPane.CANCEL_OPTION); // bummer! // this is to test importing a class and only calling a static method on it // Buz.doSomething(); // this is to test NOT importing classes which are fully qualified in the class body // java.sql.Date sqlDate = new java.sql.Date(20); // Date javaDate = new Date(); throw new IllegalArgumentException(); }
@Test public void recordThread16() { _threads.add(Thread.currentThread()); }