Example usage for junit.framework AssertionFailedError AssertionFailedError

List of usage examples for junit.framework AssertionFailedError AssertionFailedError

Introduction

In this page you can find the example usage for junit.framework AssertionFailedError AssertionFailedError.

Prototype

public AssertionFailedError(String message) 

Source Link

Usage

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

@Step
public static void assertPmNotExistInDrafts(PrivateMessage pm) {
    info("Asserting that PM doesn't exist in drafts folder");
    mainPage.openPrivateMessages();//ww w.  ja v a  2s  .  c  o  m
    pmPage.clickOpenDrafts();
    if (pmExists(pm)) {
        throw new AssertionFailedError("The PM is present in drafts folder. " + "Receiver: [" + pm.getReceiver()
                + "], " + "Subject: [" + StringUtils.left(pm.getMessageSubject(), 10) + "], " + "Content: ["
                + StringUtils.left(pm.getMessageContent(), 10) + "]");
    }
    info("Success. PM doesn't exist in drafts folder.");
}

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

@Step
public static void assertPmCounter(int expectedCounter) {
    int actualCounter = pmPage.getMessagesCounter();
    info("Checking PM counter. Expected: " + expectedCounter + ", actual: " + actualCounter);
    if (expectedCounter != actualCounter) {
        throw new AssertionFailedError("Actual PM counter differs from the expected value");
    }/*w  w w. j  a  va2 s .  c  o  m*/
    info("Success. Expected counter equals actual number.");
}

From source file:org.kuali.kra.infrastructure.TestUtilities.java

License:asdf

/**
 * Checks that the document is at a node with the given name.  This does not check that the document is at
 * the given node and only the given node, the document can be at other nodes as well and this assertion
 * will still pass./*from  ww  w . jav  a2 s. co m*/
 */
public static void assertAtNode(String message, WorkflowDocument document, String nodeName)
        throws WorkflowException {
    Set<String> nodeNames = document.getNodeNames();
    Iterator<String> nodeNameIterator = nodeNames.iterator();
    while (nodeNameIterator.hasNext()) {
        String docNodeName = nodeNameIterator.next();
        if (docNodeName.equals(nodeName)) {
            return;
        }
    }
    throw new AssertionFailedError((StringUtils.isEmpty(message) ? "" : message + ": ") + "Was ["
            + StringUtils.join(nodeNames, ", ") + "], Expected " + nodeName);
}

From source file:org.nuxeo.runtime.test.Failures.java

/**
 * Call {@link org.junit.Assert#fail(String)} with a nice expanded string if there are failures. It also replaces
 * original failure messages with a custom one if originalMessage is not {@code null}.
 *
 * @param originalMessage Message to replace if found in a failure
 * @param customMessage Custom message to use as replacement for originalMessage
 *///  w  w  w . jav a2  s  . co m
public void fail(String originalMessage, String customMessage) {
    if (failures.isEmpty()) {
        Assert.fail(customMessage);
    }
    StringBuffer buffer = new StringBuffer();
    int i = 1;
    AssertionFailedError errors = new AssertionFailedError(customMessage);
    buffer.append(customMessage);
    for (Failure failure : failures) {
        buffer.append("\n* Failure " + i + ": ");
        String trace = failure.getTrace();
        if (originalMessage != null && originalMessage.equals(failure.getMessage())) {
            trace.replaceAll(originalMessage, customMessage);
        }
        buffer.append(failure.getTestHeader()).append("\n").append(trace);
        errors.addSuppressed(failure.getException());
        i++;
    }
    // Log because JUnit swallows some parts of the stack trace
    log.debug(errors.getMessage(), errors);
    Assert.fail(buffer.toString());
}

From source file:org.opennms.netmgt.xmlrpcd.XmlrpcAnticipator.java

public synchronized void verifyAnticipated() {
    StringBuffer problems = new StringBuffer();

    if (m_anticipated.size() > 0) {
        problems.append(m_anticipated.size() + " expected calls still outstanding:\n");
        problems.append(listCalls("\t", m_anticipated));
    }/*from ww w .  j  av a2 s . co m*/
    if (m_unanticipated.size() > 0) {
        problems.append(m_unanticipated.size() + " unanticipated calls received:\n");
        problems.append(listCalls("\t", m_unanticipated));
    }

    if (problems.length() > 0) {
        problems.deleteCharAt(problems.length() - 1);
        problems.insert(0, "XML-RPC Anticipator listening at port " + m_port + " has:\n");
        throw new AssertionFailedError(problems.toString());
    }
}

From source file:org.opennms.test.mock.MockLogAppender.java

/**
 * <p>assertNotGreaterOrEqual</p>
 *
 * @param level a {@link org.apache.log4j.Level} object.
 * @throws junit.framework.AssertionFailedError if any.
 *///from ww  w .  j a  v  a2  s. c o m
public static void assertNotGreaterOrEqual(final Level level) throws AssertionFailedError {
    if (!isLoggingSetup()) {
        throw new AssertionFailedError("MockLogAppender has not been initialized");
    }

    try {
        Thread.sleep(500);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    final LoggingEvent[] events = getEventsGreaterOrEqual(level);
    if (events.length == 0) {
        return;
    }

    StringBuffer message = new StringBuffer("Log messages at or greater than the log level ").append(level)
            .append(" received:");

    for (final LoggingEvent event : events) {
        message.append("\n\t[").append(event.getLevel()).append("] ").append(event.getLoggerName()).append(": ")
                .append(event.getMessage());
    }

    throw new AssertionFailedError(message.toString());
}

From source file:org.opennms.test.mock.MockLogAppender.java

/**
 * <p>assertLogAtLevel</p>/*from   w  w w .j a v a  2s. com*/
 * Asserts that a message was logged at the requested level.
 * 
 * Useful for testing code that *should* have logged an error message 
 * (or a notice or some other special case)
 *
 * @param level a {@link org.apache.log4j.Level} object.
 * @throws junit.framework.AssertionFailedError if any.
 */
public static void assertLogAtLevel(final Level level) throws AssertionFailedError {
    if (!isLoggingSetup()) {
        throw new AssertionFailedError("MockLogAppender has not been initialized");
    }

    try {
        Thread.sleep(500);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    final LoggingEvent[] events = getEventsAtLevel(level);
    if (events.length == 0) {
        throw new AssertionFailedError("No messages were received at level " + level);
    }

}

From source file:org.smartfrog.test.SmartFrogTestManager.java

/**
 * Deploys an application and returns the reference to deployed application.
 *
 * @param testURL URL to test//w  w  w .  j  ava  2  s  .  co  m
 * @param appName Application name
 *
 * @return Reference to deployed application
 *
 * @throws RemoteException in the event of remote trouble.
 */
@SuppressWarnings({ "ProhibitedExceptionThrown" })
protected Prim deployExpectingSuccess(String testURL, String appName) throws Throwable {
    try {
        Object deployedApp = deployApplication(appName, testURL);

        if (deployedApp instanceof Prim) {
            return ((Prim) deployedApp);
        } else {
            lookForThrowableInDeployment(deployedApp);
            throw new AssertionFailedError(
                    "Deployed something of type " + deployedApp.getClass() + ": " + deployedApp);
        }
    } catch (Throwable throwable) {
        logThrowable("thrown during deployment", throwable);
        throw throwable;
    }
}

From source file:org.smartfrog.test.SmartFrogTestManager.java

/**
 * assert that a string contains a substring
 *
 * @param source     source to scan// w  w w .  ja  va  2s.  c om
 * @param substring  string to look for
 * @param resultMessage configuration description
 * @param exception  any exception to look at can be null
 */
public void assertContains(String source, String substring, String resultMessage, Throwable exception) {
    assertNotNull("No string to look for [" + substring + "]", source);
    assertNotNull("No substring ", substring);
    final boolean contained = source.contains(substring);

    if (!contained) {
        String message = "- Did not find \n[" + substring + "] \nin \n[" + source + ']'
                + (resultMessage != null ? ("\n, Result:\n" + resultMessage) : "");
        if (exception != null) {
            log.error(message, exception);
        } else {
            log.error(message);
        }
        AssertionFailedError error = new AssertionFailedError(message);
        if (exception != null) {
            error.initCause(exception);
        }
        throw error;
    }
}

From source file:org.smartfrog.test.SmartFrogTestManager.java

/**
 * Fail if a condition is not met; the message raised includes the message and the string value of the event.
 *
 * @param test    condition to evaluate/*w  w  w .ja v  a 2  s . c  om*/
 * @param message message to print
 * @param event   related event
 * @throws AssertionFailedError if the condition is true
 */
public void conditionalFail(boolean test, String message, String eventHistory, LifecycleEvent event) {
    if (test) {
        AssertionFailedError afe = new AssertionFailedError(message + "\nEvent is " + event
                + (eventHistory != null ? ("\nHistory:\n" + eventHistory) : ""));
        TerminationRecord tr = event.getStatus();
        if (tr != null) {
            afe.initCause(tr.getCause());
        }
        throw afe;
    }
}