Beispiel #1
0
  public static void assertEqualsToFile(
      @NotNull File expectedFile,
      @NotNull String actual,
      @NotNull Function1<String, String> sanitizer) {
    try {
      String actualText =
          JetTestUtilsKt.trimTrailingWhitespacesAndAddNewlineAtEOF(
              StringUtil.convertLineSeparators(actual.trim()));

      if (!expectedFile.exists()) {
        FileUtil.writeToFile(expectedFile, actualText);
        Assert.fail("Expected data file did not exist. Generating: " + expectedFile);
      }
      String expected = FileUtil.loadFile(expectedFile, CharsetToolkit.UTF8, true);

      String expectedText =
          JetTestUtilsKt.trimTrailingWhitespacesAndAddNewlineAtEOF(
              StringUtil.convertLineSeparators(expected.trim()));

      if (!Comparing.equal(sanitizer.invoke(expectedText), sanitizer.invoke(actualText))) {
        throw new FileComparisonFailure(
            "Actual data differs from file content: " + expectedFile.getName(),
            expected,
            actual,
            expectedFile.getAbsolutePath());
      }
    } catch (IOException e) {
      throw ExceptionUtilsKt.rethrow(e);
    }
  }
 private void verifyJavaDoc(final PsiElement field) throws IOException {
   final File htmlPath =
       new File(
           JavaTestUtil.getJavaTestDataPath()
               + "/codeInsight/javadocIG/"
               + getTestName(true)
               + ".html");
   String htmlText = FileUtil.loadFile(htmlPath);
   String docInfo = new JavaDocInfoGenerator(getProject(), field).generateDocInfo(null);
   assertNotNull(docInfo);
   assertEquals(
       StringUtil.convertLineSeparators(htmlText.trim()),
       StringUtil.convertLineSeparators(docInfo.trim()));
 }
  @Test
  public void testSkipMethodAfterStartTest() throws Exception {
    final StringBuffer buf = new StringBuffer();
    final IDEATestNGRemoteListener listener = createListener(buf);
    listener.onStart((ISuite) null);
    final MockTestNGResult result = new MockTestNGResult("ATest", "testName");
    listener.onTestStart(result);
    listener.onTestSkipped(result);
    listener.onFinish((ISuite) null);

    Assert.assertEquals(
        "output: " + buf,
        "##teamcity[enteredTheMatrix]\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://ATest']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.testName' locationHint='java:test://ATest.testName|[0|]']\n"
            + "\n"
            + "##teamcity[testIgnored name='ATest.testName']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.testName']\n"
            + "##teamcity[testSuiteFinished name='ATest']\n",
        StringUtil.convertLineSeparators(buf.toString()));
  }
  public void parseSegments() {
    if (!toParseSegments) {
      return;
    }
    if (mySegments != null) {
      return;
    }

    if (myString == null) myString = "";
    myString = StringUtil.convertLineSeparators(myString);
    mySegments = new ArrayList<Segment>();
    StringBuilder buffer = new StringBuilder("");
    TemplateTextLexer lexer = new TemplateTextLexer();
    lexer.start(myString);

    while (true) {
      IElementType tokenType = lexer.getTokenType();
      if (tokenType == null) break;
      int start = lexer.getTokenStart();
      int end = lexer.getTokenEnd();
      String token = myString.substring(start, end);
      if (tokenType == TemplateTokenType.VARIABLE) {
        String name = token.substring(1, token.length() - 1);
        Segment segment = new Segment(name, buffer.length());
        mySegments.add(segment);
      } else if (tokenType == TemplateTokenType.ESCAPE_DOLLAR) {
        buffer.append("$");
      } else {
        buffer.append(token);
      }
      lexer.advance();
    }
    myTemplateText = buffer.toString();
  }
 public void testPackageInfo() throws Exception {
   final String path = JavaTestUtil.getJavaTestDataPath() + "/codeInsight/javadocIG/";
   final String packageInfo = path + getTestName(true);
   PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete);
   final String info =
       new JavaDocInfoGenerator(
               getProject(),
               JavaPsiFacade.getInstance(getProject()).findPackage(getTestName(true)))
           .generateDocInfo(null);
   String htmlText =
       FileUtil.loadFile(new File(packageInfo + File.separator + "packageInfo.html"));
   assertNotNull(info);
   assertEquals(
       StringUtil.convertLineSeparators(htmlText.trim()),
       StringUtil.convertLineSeparators(info.trim()));
 }
  private static void doTest(XmlSuite suite, String expected) {
    final StringBuffer buf = new StringBuffer();
    final IDEATestNGRemoteListener listener = createListener(buf);

    for (XmlTest test : suite.getTests()) {
      for (XmlClass aClass : test.getClasses()) {
        final String classFQName = aClass.getName();
        for (XmlInclude include : aClass.getIncludedMethods()) {
          final String methodName = include.getName();
          List<Integer> numbers = include.getInvocationNumbers();
          if (numbers.isEmpty()) {
            numbers = Collections.singletonList(0);
          }
          for (Integer integer : numbers) {
            final MockTestNGResult result =
                new MockTestNGResult(classFQName, methodName, null, new Object[] {integer});
            listener.onTestStart(result);
            listener.onTestFinished(result);
          }
        }
      }
    }

    Assert.assertEquals(
        "output: " + buf, expected, StringUtil.convertLineSeparators(buf.toString()));
  }
  /**
   * Validates that content of the editor as well as caret and selection matches one specified in
   * data file that should be formed with the same format as one used in configureByFile
   *
   * @param message - this check specific message. Added to text, caret position, selection
   *     checking. May be null
   * @param filePath - relative path from %IDEA_INSTALLATION_HOME%/testData/
   * @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped
   *     prior to comparing.
   */
  protected void checkResultByFile(
      @Nullable String message,
      @TestDataFile @NotNull String filePath,
      final boolean ignoreTrailingSpaces) {
    bringRealEditorBack();

    getProject().getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
    if (ignoreTrailingSpaces) {
      final Editor editor = myEditor;
      TrailingSpacesStripper.stripIfNotCurrentLine(editor.getDocument(), false);
      EditorUtil.fillVirtualSpaceUntilCaret(editor);
    }

    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

    String fullPath = getTestDataPath() + filePath;

    File ioFile = new File(fullPath);

    assertTrue(getMessage("Cannot find file " + fullPath, message), ioFile.exists());
    String fileText = null;
    try {
      fileText = FileUtil.loadFile(ioFile, CharsetToolkit.UTF8_CHARSET);
    } catch (IOException e) {
      LOG.error(e);
    }
    checkResultByText(
        message,
        StringUtil.convertLineSeparators(fileText),
        ignoreTrailingSpaces,
        getTestDataPath() + "/" + filePath);
  }
  @NotNull
  private static String findMainClass(VirtualFile gradleHome, VirtualFile script, Project project) {
    final String userDefined = System.getProperty("gradle.launcher.class");
    if (StringUtil.isNotEmpty(userDefined)) {
      return userDefined;
    }

    VirtualFile launcher = gradleHome.findFileByRelativePath("bin/gradle");
    if (launcher == null) {
      launcher = gradleHome.findFileByRelativePath("bin/gradle.bat");
    }
    if (launcher != null) {
      try {
        final String text = StringUtil.convertLineSeparators(VfsUtilCore.loadText(launcher));
        final Matcher matcher = MAIN_CLASS_NAME_PATTERN.matcher(text);
        if (matcher.find()) {
          String candidate = matcher.group(1);
          if (StringUtil.isNotEmpty(candidate)) {
            return candidate;
          }
        }
      } catch (IOException ignored) {
      }
    }

    final PsiFile grFile = PsiManager.getInstance(project).findFile(script);
    if (grFile != null
        && JavaPsiFacade.getInstance(project)
                .findClass("org.gradle.BootstrapMain", grFile.getResolveScope())
            != null) {
      return "org.gradle.BootstrapMain";
    }

    return "org.gradle.launcher.GradleMain";
  }
  @Test
  public void testFailureWithoutStart() throws Exception {

    final StringBuffer buf = new StringBuffer();
    final IDEATestNGRemoteListener listener = createListener(buf);
    listener.onStart((ISuite) null);
    listener.onTestFailure(
        new MockTestNGResult(
            "ATest", "testName", createExceptionWithoutTrace(), ArrayUtil.EMPTY_OBJECT_ARRAY));
    listener.onFinish((ISuite) null);

    Assert.assertEquals(
        "output: " + buf,
        "##teamcity[enteredTheMatrix]\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://ATest']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.testName' locationHint='java:test://ATest.testName|[0|]']\n"
            + "##teamcity[testFailed name='ATest.testName' details='java.lang.Exception|n' error='true' message='']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.testName']\n"
            + "##teamcity[testSuiteFinished name='ATest']\n",
        StringUtil.convertLineSeparators(buf.toString()));
  }
  protected void setUp(TestUtils.ScalaSdkVersion version) throws Exception {
    super.setUp(version);
    final SyntheticClasses syntheticClasses =
        getProjectAdapter().getComponent(SyntheticClasses.class);
    if (!syntheticClasses.isClassesRegistered()) {
      syntheticClasses.registerClasses();
    }

    String extention = ".scala";
    String fileName = getTestName(false);
    if (fileName.startsWith("JavaFileWithName")) {
      extention = ".java";
      fileName = fileName.substring("JavaFileWithName".length());
    }
    String filePath = folderPath() + File.separator + fileName + extention;
    File ioFile = new File(filePath);
    String fileText = FileUtil.loadFile(ioFile, CharsetToolkit.UTF8);
    fileText = StringUtil.convertLineSeparators(fileText);
    int offset = fileText.indexOf("<ref>");
    fileText = fileText.replace("<ref>", "");
    configureFromFileTextAdapter(ioFile.getName(), fileText);
    if (offset != -1) {
      getEditor().getCaretModel().moveToOffset(offset);
    }
  }
 public void testEnumConstantOrdinal() throws Exception {
   PsiClass psiClass = getTestClass();
   PsiField field = psiClass.getFields()[0];
   final File htmlPath =
       new File(
           JavaTestUtil.getJavaTestDataPath()
               + "/codeInsight/javadocIG/"
               + getTestName(true)
               + ".html");
   String htmlText = FileUtil.loadFile(htmlPath);
   String docInfo = new JavaDocumentationProvider().getQuickNavigateInfo(field, field);
   assertNotNull(docInfo);
   assertEquals(
       StringUtil.convertLineSeparators(htmlText.trim()),
       StringUtil.convertLineSeparators(docInfo.trim()));
 }
  public static List<String> readInput(String filePath) {
    String content;
    try {
      content = StringUtil.convertLineSeparators(FileUtil.loadFile(new File(filePath)));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    Assert.assertNotNull(content);

    List<String> input = new ArrayList<String>();

    int separatorIndex;
    content = StringUtil.replace(content, "\r", ""); // for MACs

    // Adding input  before -----
    while ((separatorIndex = content.indexOf("-----")) >= 0) {
      input.add(content.substring(0, separatorIndex - 1));
      content = content.substring(separatorIndex);
      while (StringUtil.startsWithChar(content, '-')) {
        content = content.substring(1);
      }
      if (StringUtil.startsWithChar(content, '\n')) {
        content = content.substring(1);
      }
    }
    input.add(content);

    Assert.assertTrue("No data found in source file", input.size() > 0);
    Assert.assertNotNull("Test output points to null", input.size() > 1);

    return input;
  }
Beispiel #13
0
 private Document documentFromRevision(final ContentRevision cr) throws VcsException {
   final Document oldDocument =
       new DocumentImpl(StringUtil.convertLineSeparators(notNullContentRevision(cr)), true);
   // todo !!! a question how to show line separators in diff etc
   // todo currently document doesn't allow to put \r as separator
   oldDocument.setReadOnly(true);
   return oldDocument;
 }
 @Override
 public void setText(@NotNull CharSequence text) {
   String s = StringUtil.convertLineSeparators(text.toString());
   myChars = new char[s.length()];
   s.getChars(0, s.length(), myChars, 0);
   myString = new String(myChars);
   myLineSet = LineSet.createLineSet(myString);
 }
 private static String loadFile(String name) {
   String fullName = BASE_PATH + File.separatorChar + name;
   try {
     String text = FileUtil.loadFile(new File(fullName));
     return StringUtil.convertLineSeparators(text);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
 private static String loadText(URL url) {
   String text = "";
   try {
     text = StringUtil.convertLineSeparators(UrlUtil.loadText(url));
   } catch (IOException e) {
     LOG.error(e);
   }
   return text;
 }
  private static void assertUnorderedLinesWithFile(String filePath, String actualText) {
    String fileText;
    try {
      if (OVERWRITE_TESTDATA) {
        VfsTestUtil.overwriteTestData(filePath, actualText);
        System.out.println("File " + filePath + " created.");
      }
      fileText = FileUtil.loadFile(new File(filePath), CharsetToolkit.UTF8_CHARSET);
    } catch (FileNotFoundException e) {
      VfsTestUtil.overwriteTestData(filePath, actualText);
      throw new AssertionFailedError("No output text found. File " + filePath + " created.");
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    String expected = StringUtil.convertLineSeparators(fileText.trim());
    String actual = StringUtil.convertLineSeparators(actualText.trim());

    assertUnorderedElementsAreEqual(expected.split("\n"), actual.split("\n"));
  }
 public void testClassTypeParamsPresentation() throws Exception {
   PsiClass psiClass = getTestClass();
   final PsiReferenceList extendsList = psiClass.getExtendsList();
   final PsiJavaCodeReferenceElement referenceElement = extendsList.getReferenceElements()[0];
   final PsiClass superClass = extendsList.getReferencedTypes()[0].resolve();
   final File htmlPath =
       new File(
           JavaTestUtil.getJavaTestDataPath()
               + "/codeInsight/javadocIG/"
               + getTestName(true)
               + ".html");
   String htmlText = FileUtil.loadFile(htmlPath);
   String docInfo =
       new JavaDocumentationProvider().getQuickNavigateInfo(superClass, referenceElement);
   assertNotNull(docInfo);
   assertEquals(
       StringUtil.convertLineSeparators(htmlText.trim()),
       StringUtil.convertLineSeparators(docInfo.trim()));
 }
 protected static void assertSameLinesWithFile(String filePath, String actualText) {
   String fileText;
   try {
     if (OVERWRITE_TESTDATA) {
       VfsTestUtil.overwriteTestData(filePath, actualText);
       System.out.println("File " + filePath + " created.");
     }
     fileText = FileUtil.loadFile(new File(filePath), CharsetToolkit.UTF8);
   } catch (FileNotFoundException e) {
     VfsTestUtil.overwriteTestData(filePath, actualText);
     throw new AssertionFailedError("No output text found. File " + filePath + " created.");
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   String expected = StringUtil.convertLineSeparators(fileText.trim());
   String actual = StringUtil.convertLineSeparators(actualText.trim());
   if (!Comparing.equal(expected, actual)) {
     throw new FileComparisonFailure(null, expected, actual, filePath);
   }
 }
 protected void doFileTest(@NonNls String fileExt) {
   String fileName =
       PathManager.getHomePath() + "/" + getDirPath() + "/" + getTestName(true) + "." + fileExt;
   String text = "";
   try {
     String fileText = FileUtil.loadFile(new File(fileName));
     text = StringUtil.convertLineSeparators(shouldTrim() ? fileText.trim() : fileText);
   } catch (IOException e) {
     fail("can't load file " + fileName + ": " + e.getMessage());
   }
   doTest(text);
 }
  private void doQuickDocGenerationTestWithCheckExpectedResult(
      Object completionVariant, final String... baseFileNames) throws Exception {
    final DocumentationTestContext context = new DocumentationTestContext(baseFileNames);
    String pathname = getTestDataPath() + baseFileNames[0] + ".expected.html";
    VirtualFile vfile = LocalFileSystem.getInstance().findFileByIoFile(new File(pathname));
    assertNotNull(pathname + " not found", vfile);
    String expectedText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(vfile));
    assertEquals(expectedText, StringUtil.convertLineSeparators(context.generateDoc()));

    if (completionVariant != null) {
      vfile =
          LocalFileSystem.getInstance()
              .findFileByIoFile(
                  new File(getTestDataPath() + baseFileNames[0] + ".expected.completion.html"));
      expectedText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(vfile), "\n");
      assertEquals(
          expectedText,
          StringUtil.convertLineSeparators(
              context.generateDocForCompletion(completionVariant), "\n"));
    }
  }
 @NotNull
 public String getSelectedText() {
   StringBuilder sb = new StringBuilder();
   boolean first = true;
   for (Object o : myList.getSelectedValues()) {
     if (first) first = false;
     else sb.append("\n");
     String s = ((Item) o).longText;
     sb.append(StringUtil.convertLineSeparators(s));
   }
   return sb.toString();
 }
  @Test
  public void testConfigurationMethods() throws Exception {
    final StringBuffer buf = new StringBuffer();
    final IDEATestNGRemoteListener listener = createListener(buf);
    final String className = "a.ATest";
    listener.onSuiteStart(className, true);
    for (String methodName : new String[] {"test1", "test2"}) {
      listener.onConfigurationSuccess(new MockTestNGResult(className, "setUp"));
      final MockTestNGResult result = new MockTestNGResult(className, methodName);
      listener.onTestStart(result);
      listener.onTestFinished(result);
      listener.onConfigurationSuccess(new MockTestNGResult(className, "tearDown"));
    }
    listener.onSuiteFinish(className);

    Assert.assertEquals(
        "output: " + buf,
        "\n"
            + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.setUp' locationHint='java:test://a.ATest.setUp']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.setUp']\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.test1' locationHint='java:test://a.ATest.test1|[0|]']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.test1']\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.tearDown' locationHint='java:test://a.ATest.tearDown']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.tearDown']\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.setUp' locationHint='java:test://a.ATest.setUp']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.setUp']\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.test2' locationHint='java:test://a.ATest.test2|[0|]']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.test2']\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.tearDown' locationHint='java:test://a.ATest.tearDown']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.tearDown']\n"
            + "##teamcity[testSuiteFinished name='a.ATest']\n",
        StringUtil.convertLineSeparators(buf.toString()));
  }
  protected void runOverEditor(
      @NotNull final Project project,
      @NotNull final Editor editor,
      @NotNull final PsiFile psiFile) {
    final Document document = editor.getDocument();
    if (!ReadonlyStatusHandler.ensureDocumentWritable(project, document)) return;

    final Runnable runnable =
        () -> {
          final int caretOffset = editor.getCaretModel().getOffset();
          final int lineLength = getRightMargin(project);

          DartAnalysisServerService.getInstance().updateFilesContent();
          DartAnalysisServerService.FormatResult formatResult =
              DartAnalysisServerService.getInstance()
                  .edit_format(psiFile.getVirtualFile(), caretOffset, 0, lineLength);

          if (formatResult == null) {
            showHintLater(editor, DartBundle.message("dart.style.hint.failed"), true);
            LOG.warn("Unexpected response from edit_format, formatResult is null");
            return;
          }

          final List<SourceEdit> edits = formatResult.getEdits();
          if (edits == null || edits.size() == 0) {
            showHintLater(editor, DartBundle.message("dart.style.hint.already.good"), false);
          } else if (edits.size() == 1) {
            final String replacement =
                StringUtil.convertLineSeparators(edits.get(0).getReplacement());
            document.replaceString(0, document.getTextLength(), replacement);
            final int offset =
                DartAnalysisServerService.getInstance()
                    .getConvertedOffset(psiFile.getVirtualFile(), formatResult.getOffset());
            editor.getCaretModel().moveToOffset(offset);
            showHintLater(editor, DartBundle.message("dart.style.hint.success"), false);
          } else {
            showHintLater(editor, DartBundle.message("dart.style.hint.failed"), true);
            LOG.warn(
                "Unexpected response from edit_format, formatResult.getEdits().size() = "
                    + edits.size());
          }
        };

    ApplicationManager.getApplication()
        .runWriteAction(
            () ->
                CommandProcessor.getInstance()
                    .executeCommand(
                        project, runnable, DartBundle.message("dart.style.action.name"), null));
  }
  public static void changeLineSeparators(
      @Nullable Project project,
      @NotNull VirtualFile file,
      @NotNull String newSeparator,
      @NotNull Object requestor)
      throws IOException {
    CharSequence currentText =
        getTextByBinaryPresentation(file.contentsToByteArray(), file, true, false);
    String currentSeparator = detectLineSeparator(file, false);
    if (newSeparator.equals(currentSeparator)) {
      return;
    }
    String newText = StringUtil.convertLineSeparators(currentText.toString(), newSeparator);

    file.setDetectedLineSeparator(newSeparator);
    write(project, file, requestor, newText, -1);
  }
 @Test
 public void testNullParameters() throws Exception {
   final StringBuffer buf = new StringBuffer();
   final IDEATestNGRemoteListener listener = createListener(buf);
   final MockTestNGResult result =
       new MockTestNGResult("ATest", "testMe", null, new Object[] {null, null});
   listener.onTestStart(result);
   listener.onTestFinished(result);
   Assert.assertEquals(
       "output: " + buf,
       "##teamcity[testCount count='1']\n"
           + "\n"
           + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://ATest']\n"
           + "\n"
           + "##teamcity[testStarted name='ATest.testMe|[null, null|]' locationHint='java:test://ATest.testMe|[0|]']\n"
           + "\n"
           + "##teamcity[testFinished name='ATest.testMe|[null, null|]']\n",
       StringUtil.convertLineSeparators(buf.toString()));
 }
 public void printToHistory(@NotNull final List<Pair<String, TextAttributes>> attributedText) {
   ApplicationManager.getApplication().assertIsDispatchThread();
   if (LOG.isDebugEnabled()) {
     LOG.debug("printToHistory(): " + attributedText.size());
   }
   final boolean scrollToEnd = shouldScrollHistoryToEnd();
   final int[] offsets = new int[attributedText.size() + 1];
   int i = 0;
   offsets[i] = 0;
   final StringBuilder sb = new StringBuilder();
   for (final Pair<String, TextAttributes> pair : attributedText) {
     sb.append(StringUtil.convertLineSeparators(pair.getFirst()));
     offsets[++i] = sb.length();
   }
   final DocumentEx history = myHistoryViewer.getDocument();
   final int oldHistoryLength = history.getTextLength();
   appendToHistoryDocument(history, sb.toString());
   assert oldHistoryLength + offsets[i] == history.getTextLength()
       : "unexpected history length "
           + oldHistoryLength
           + " "
           + offsets[i]
           + " "
           + history.getTextLength();
   LOG.debug("printToHistory(): text processed");
   final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true);
   i = 0;
   for (final Pair<String, TextAttributes> pair : attributedText) {
     markupModel.addRangeHighlighter(
         oldHistoryLength + offsets[i],
         oldHistoryLength + offsets[i + 1],
         HighlighterLayer.SYNTAX,
         pair.getSecond(),
         HighlighterTargetArea.EXACT_RANGE);
     ++i;
   }
   LOG.debug("printToHistory(): markup added");
   if (scrollToEnd) {
     scrollHistoryToEnd();
   }
   queueUiUpdate(scrollToEnd);
   LOG.debug("printToHistory(): completed");
 }
 public void printToHistory(String text, final TextAttributes attributes) {
   ApplicationManager.getApplication().assertIsDispatchThread();
   text = StringUtil.convertLineSeparators(text);
   final boolean scrollToEnd = shouldScrollHistoryToEnd();
   final Document history = myHistoryViewer.getDocument();
   final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true);
   final int offset = history.getTextLength();
   appendToHistoryDocument(history, text);
   markupModel.addRangeHighlighter(
       offset,
       history.getTextLength(),
       HighlighterLayer.SYNTAX,
       attributes,
       HighlighterTargetArea.EXACT_RANGE);
   if (scrollToEnd) {
     scrollHistoryToEnd();
   }
   queueUiUpdate(scrollToEnd);
 }
 protected void assertOutput(String className, String expected, final Module module)
     throws ExecutionException {
   final StringBuffer sb = new StringBuffer();
   ProcessHandler process =
       runProcess(
           className,
           module,
           DefaultRunExecutor.class,
           new ProcessAdapter() {
             @Override
             public void onTextAvailable(ProcessEvent event, Key outputType) {
               if (ProcessOutputTypes.SYSTEM != outputType) {
                 sb.append(event.getText());
               }
             }
           },
           ProgramRunner.PROGRAM_RUNNER_EP.findExtension(DefaultJavaProgramRunner.class));
   process.waitFor();
   assertEquals(expected.trim(), StringUtil.convertLineSeparators(sb.toString().trim()));
 }
  @Test
  public void testParallelTestExecutionPreserveInvocationCount() throws Exception {
    final StringBuffer buf = new StringBuffer();
    final IDEATestNGRemoteListener listener = createListener(buf);
    listener.onStart((ISuite) null);
    final MockTestNGResult[] results =
        new MockTestNGResult[] {
          new MockTestNGResult("ATest", "testName"),
          new MockTestNGResult("ATest", "testName1"),
          new MockTestNGResult("ATest", "testName")
        };
    for (MockTestNGResult result : results) {
      listener.onTestStart(result);
      listener.onTestFinished(result);
    }
    listener.onFinish((ISuite) null);

    Assert.assertEquals(
        "output: " + buf,
        "##teamcity[enteredTheMatrix]\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://ATest']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.testName' locationHint='java:test://ATest.testName|[0|]']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.testName']\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.testName1' locationHint='java:test://ATest.testName1|[0|]']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.testName1']\n"
            + "##teamcity[testCount count='1']\n"
            + "\n"
            + "##teamcity[testStarted name='ATest.testName (1)' locationHint='java:test://ATest.testName|[1|]']\n"
            + "\n"
            + "##teamcity[testFinished name='ATest.testName (1)']\n"
            + "##teamcity[testSuiteFinished name='ATest']\n",
        StringUtil.convertLineSeparators(buf.toString()));
  }