protected static void appendCondition(ICBreakpoint breakpoint, StringBuffer buffer)
     throws CoreException {
   String condition = breakpoint.getCondition();
   if (condition != null && condition.length() > 0) {
     buffer.append(' ');
     buffer.append(
         MessageFormat.format(
             DebugCoreMessages.getString("CDebugUtils.4"),
             new Object[] {condition})); // $NON-NLS-1$
   }
 }
  private void testConsoleBreakpoint(
      Class<? extends ICBreakpoint> type, Map<String, Object> attributes) throws Throwable {
    // Set a console breakpoint and verify that
    // the corresponding platform breakpoint is created
    // and its install count is 1 if the breakpoint is installed
    // and 0 if the breakpoint is pending.
    // Check for a duplicate target breakpoint.
    setConsoleBreakpoint(type, attributes);
    MIBreakpoint[] miBpts = getTargetBreakpoints();
    Assert.assertTrue(miBpts.length == 1);
    waitForBreakpointEvent(IBreakpointsAddedEvent.class);
    Assert.assertTrue(getPlatformBreakpointCount() == 1);
    ICBreakpoint plBpt = findPlatformBreakpoint(type, attributes);
    Assert.assertTrue(plBpt instanceof CBreakpoint);
    // We can't rely on IBreakpointsAddedEvent because it is fired
    // before the install count is incremented.
    if (!miBpts[0].isPending()) {
      // If the target breakpoint is not pending wait
      // until the install count becomes 1.
      waitForInstallCountChange((CBreakpoint) plBpt, 1);
    } else {
      // For pending breakpoints the install count is expected to remain
      // unchanged. Give it some time and verify that it is 0.
      Thread.sleep(1000);
      Assert.assertTrue(((CBreakpoint) plBpt).getInstallCount() == 0);
    }

    // Disable the console breakpoint and verify that
    // the platform breakpoint is disabled.
    enableConsoleBreakpoint(miBpts[0].getNumber(), false);
    waitForBreakpointEvent(IBreakpointsUpdatedEvent.class);
    Assert.assertTrue(!plBpt.isEnabled());

    // Enable the console breakpoint and verify that
    // the platform breakpoint is enabled.
    enableConsoleBreakpoint(miBpts[0].getNumber(), true);
    waitForBreakpointEvent(IBreakpointsUpdatedEvent.class);
    Assert.assertTrue(plBpt.isEnabled());

    // Set the ignore count of the console breakpoint and
    // verify that the platform breakpoint's ignore count
    // is updated.
    setConsoleBreakpointIgnoreCount(miBpts[0].getNumber(), 5);
    waitForBreakpointEvent(IBreakpointsUpdatedEvent.class);
    Assert.assertTrue(plBpt.getIgnoreCount() == 5);

    // Reset the ignore count of the console breakpoint and
    // verify that the platform breakpoint's ignore count
    // is updated.
    setConsoleBreakpointIgnoreCount(miBpts[0].getNumber(), 0);
    waitForBreakpointEvent(IBreakpointsUpdatedEvent.class);
    Assert.assertTrue(plBpt.getIgnoreCount() == 0);

    // Set the condition of the console breakpoint and
    // verify that the platform breakpoint's condition
    // is updated.
    setConsoleBreakpointCondition(miBpts[0].getNumber(), "path==0");
    waitForBreakpointEvent(IBreakpointsUpdatedEvent.class);
    Assert.assertTrue(plBpt.getCondition().equals("path==0"));

    // Reset the condition of the console breakpoint and
    // verify that the platform breakpoint's condition
    // is updated.
    setConsoleBreakpointCondition(miBpts[0].getNumber(), "");
    waitForBreakpointEvent(IBreakpointsUpdatedEvent.class);
    Assert.assertTrue(plBpt.getCondition().isEmpty());

    // Delete the console breakpoint and verify that
    // the install count of the platform breakpoint is 0.
    deleteConsoleBreakpoint(miBpts[0].getNumber());
    waitForBreakpointEvent(IBreakpointsRemovedEvent.class);
    Assert.assertTrue(getPlatformBreakpointCount() == 1);
    plBpt = findPlatformBreakpoint(type, attributes);
    Assert.assertTrue(plBpt instanceof CBreakpoint);
    waitForInstallCountChange((CBreakpoint) plBpt, 0);

    // Make sure the breakpoint does not get re-installed
    // once it gets a notification that the platform bp changed
    // (through its install count changing) Bug 433044
    // Give it some time and verify that it is still 0.
    Thread.sleep(3000); // One second was not enough
    Assert.assertTrue("Install count no longer 0", ((CBreakpoint) plBpt).getInstallCount() == 0);

    // Set the console breakpoint again and verify that
    // the install count of the platform breakpoint is 1
    // for installed breakpoints and 0 for pending breakpoints.
    setConsoleBreakpoint(type, attributes);
    miBpts = getTargetBreakpoints();
    Assert.assertTrue(miBpts.length == 1);
    waitForBreakpointEvent(IBreakpointsAddedEvent.class);
    Assert.assertTrue(getPlatformBreakpointCount() == 1);

    // Give a little delay to allow queued Executor operations
    // to complete before deleting the breakpoint again.
    // If we don't we may delete it so fast that the MIBreakpointsManager
    // has not yet updated its data structures
    // Bug 438934 comment 10
    Thread.sleep(500);

    plBpt = findPlatformBreakpoint(type, attributes);
    Assert.assertTrue(plBpt instanceof CBreakpoint);
    if (!miBpts[0].isPending()) {
      waitForInstallCountChange((CBreakpoint) plBpt, 1);
    } else {
      // For pending breakpoints the install count is expected to remain
      // unchanged. Give it some time and verify that it is 0.
      Thread.sleep(1000);
      Assert.assertTrue(((CBreakpoint) plBpt).getInstallCount() == 0);
    }

    // Remove the platform breakpoint and verify that
    // the target breakpoint is deleted.
    deletePlatformBreakpoint(plBpt);

    // Don't fail right away if we don't get the breakpoint event
    // as we can't tell the true cause.
    // Let further checks happen to help figure things out.

    String failure = "";
    try {
      waitForBreakpointEvent(IBreakpointsRemovedEvent.class);
    } catch (Exception e) {
      failure += e.getMessage();
    }

    int platformBp = getPlatformBreakpointCount();
    if (platformBp != 0) {
      if (!failure.isEmpty()) failure += ", ";
      failure += "Platform breakpoints remaining: " + platformBp;
    }

    miBpts = getTargetBreakpoints();
    if (miBpts.length != 0) {
      if (!failure.isEmpty()) failure += ", ";
      failure += "Target breakpoints remaining: " + miBpts.length;
    }

    Assert.assertTrue(failure, failure.isEmpty());
  }