public void assertAnnotationNotContains(String filename, String content, String contains) { for (Annotation annotation : getAnnotationsAtCaret(filename, content)) { if(annotation.getMessage().contains(contains)) { fail(String.format("Fail not matching '%s' with '%s'", contains, annotation)); } } }
public void assertAnnotationContains(String filename, String content, String contains) { List<String> matches = new ArrayList<String>(); for (Annotation annotation : getAnnotationsAtCaret(filename, content)) { matches.add(annotation.toString()); if(annotation.getMessage().contains(contains)) { return; } } fail(String.format("Fail matches '%s' with one of %s", contains, matches)); }
/** * @see TemplateAnnotationAnnotator#annotate */ public void testThatTemplateCreationAnnotationProvidesQuickfix() { PsiFile psiFile = myFixture.configureByText("foobar.php", "<?php\n" + "use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template;\n" + "\n" + "class Foobar\n" + "{\n" + " /**\n" + " * @Temp<caret>late(\"foobar.html.twig\")\n" + " */\n" + " public function fooAction()\n" + " {\n" + " }\n" + "}\n" + "" ); PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); PsiElement phpDocTag = psiElement.getParent(); AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile)); new TemplateAnnotationAnnotator().annotate(new PhpAnnotationDocTagAnnotatorParameter( PhpIndex.getInstance(getProject()).getAnyByFQN(TwigUtil.TEMPLATE_ANNOTATION_CLASS).iterator().next(), (PhpDocTag) phpDocTag, annotations )); assertNotNull( annotations.stream().findFirst().filter(annotation -> annotation.getMessage().contains("Create Template")) ); }
annotations.stream().findFirst().filter(annotation -> annotation.getMessage().contains("Create Template")) );
@Test public void testRangeIssues() { createStoredIssues(5); annotator.apply(psiFile, ctx, holder); for (int i = 0; i < 5; i++) { assertThat(holder.get(i).getStartOffset()).isEqualTo(i); assertThat(holder.get(i).getEndOffset()).isEqualTo(i + 10); assertThat(holder.get(i).getMessage()).contains("issue " + i); assertThat(holder.get(i).getSeverity()).isEqualTo(HighlightSeverity.WARNING); assertThat(holder.get(i).isFileLevelAnnotation()).isFalse(); } }
@Test public void testFileLevelIssues() { createFileIssues(5); annotator.apply(psiFile, ctx, holder); assertThat(holder).hasSize(5); for (int i = 0; i < 5; i++) { assertThat(holder.get(i).getStartOffset()).isEqualTo(psiFileRange.getStartOffset()); assertThat(holder.get(i).getEndOffset()).isEqualTo(psiFileRange.getEndOffset()); assertThat(holder.get(i).isFileLevelAnnotation()).isTrue(); assertThat(holder.get(i).getMessage()).contains("issue " + i); assertThat(holder.get(i).getSeverity()).isEqualTo(HighlightSeverity.WARNING); } }