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:com.meltmedia.cadmium.blackbox.test.CadmiumAssertions.java

/**
 * <p>Asserts the a file exists locally.</p>
 * @param message The message that will be in the error if the file doesn't exist.
 * @param toCheck The file to check.//from  w w  w .j  a  v  a2 s. c  o m
 */
public static void assertExistsLocally(String message, File toCheck) {
    if (toCheck == null || !toCheck.exists()) {
        throw new AssertionFailedError(message);
    }
}

From source file:rascal.AssertThrowsWithCause.java

@Override
protected void checkExceptionExpectations(Exception actualException) {
    super.checkExceptionExpectations(actualException);
    if (actualException.getCause() == null
            || !getExpectedCauseException().isAssignableFrom(actualException.getCause().getClass())) {
        throw new AssertionFailedError(String.format("Should have thrown exception with cause [%s]",
                getExpectedCauseException().getName()));
    }//from  w  w  w  .  j ava2  s.  c  om
}

From source file:org.usapi.BaseSeleniumTestTest.java

@Test
public void testAssertAlert(String msg) throws Exception {
    try {// w w  w . j  a  v  a 2 s.co  m
        myTest.assertAlert("alertText");
    } catch (USAPIException e) {
        throw new AssertionFailedError("Failed assertion: alert message");
    }

    boolean assertionThrown = false;
    try {
        myTest.assertAlert("some other alert text, dufus");
    } catch (USAPIException e) {
        assertionThrown = true;
    }
    assertTrue("Failed alert assetion did not throw exception", assertionThrown);
}

From source file:com.meltmedia.cadmium.blackbox.test.CadmiumAssertions.java

/**
 * <p>Asserts that a remote resource exists.</p>
 * @param message The message that will be in the error if the remote resource doesn't exist.
 * @param remoteLocation A string containing the URL location of the remote resource to check.
 * @param username The Basic HTTP auth username.
 * @param password The Basic HTTP auth password.
 * @return The content of the remote file.
 *//*from w ww.j  av a2 s .  c  o m*/
public static HttpEntity assertExistsRemotely(String message, String remoteLocation, String username,
        String password) {
    DefaultHttpClient client = new DefaultHttpClient();
    try {
        HttpGet get = new HttpGet(remoteLocation);
        if (!StringUtils.isEmptyOrNull(username) && !StringUtils.isEmptyOrNull(password)) {
            get.setHeader("Authorization", encodeForBasicAuth(username, password));
        }

        HttpResponse resp = client.execute(get);
        if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new AssertionFailedError(message);
        }
        return resp.getEntity();
    } catch (ClientProtocolException e) {
        throw new AssertionFailedError(e.getMessage() + ": " + message);
    } catch (IOException e) {
        throw new AssertionFailedError(e.getMessage() + ": " + message);
    }
}

From source file:net.sf.ehcache.constructs.web.AbstractWebTest.java

/**
 * Checks that the expected string occurs within the content string.
 *//*from  ww  w  .j a  v  a2 s. c o m*/
protected static void assertContains(final String string, final String content) {
    if (content.indexOf(string) == -1) {
        throw new AssertionFailedError(content + "' does not contain '" + string + "'");
    }
}

From source file:org.usapi.BaseSeleniumTestTest.java

@Test
public void testAssertFalse() {
    try {/*from   w w  w . j a va 2 s .  c  o m*/
        myTest.assertFalse("msg", false);
    } catch (USAPIException e) {
        throw new AssertionFailedError("assertFalse threw excpetion when encountering false condition");
    }
    boolean assertionThrown = false;
    try {
        myTest.assertFalse("msg", true);
    } catch (USAPIException e) {
        assertEquals(e.getMessage(), "Assertion failed: msg");
        assertionThrown = true;
    }
    assertTrue("", assertionThrown);
}

From source file:com.gargoylesoftware.htmlunit.libraries.MooTools121Test.java

/**
 * @throws Exception if an error occurs/*from w  w w. j  av a 2s.c o m*/
 */
@Test
@Tries(3)
@SuppressWarnings("unchecked")
public void mooTools() throws Exception {
    final String resource = "libraries/mootools/1.2.1/Specs/index.html";
    final URL url = getClass().getClassLoader().getResource(resource);
    assertNotNull(url);

    client_ = getWebClient();
    final HtmlPage page = client_.getPage(url);

    final HtmlElement progress = page.getElementById("progress");
    client_.waitForBackgroundJavaScriptStartingBefore(2000 * 100);

    final String prevProgress = progress.asText();

    FileUtils.writeStringToFile(new File("/tmp/mootols.html"), page.asXml());
    final String xpath = "//ul[@class='specs']/li[@class!='success']";
    final List<HtmlElement> failures = (List<HtmlElement>) page.getByXPath(xpath);
    if (!failures.isEmpty()) {
        final StringBuilder sb = new StringBuilder();
        for (HtmlElement failure : failures) {
            sb.append(failure.asXml()).append("\n\n");
        }
        throw new AssertionFailedError(sb.toString());
    }

    assertEquals("364", page.getElementById("total_examples").asText());
    assertEquals("0", page.getElementById("total_failures").asText());
    assertEquals("0", page.getElementById("total_errors").asText());
    assertEquals("100", prevProgress);
}

From source file:mesclasses.java.util.MyFXAssert.java

public static void assertText(Node node, String text) {
    try {//from   w  ww.j  ava 2s  .  c o  m
        verifyThat(node, NodeMatchers.hasText(text));
    } catch (AssertionError e) {
        if (node == null || !hasText(node)) {
            throw e;
        }
        throw new AssertionFailedError("Expecting [" + text + "] but found [" + getText(node) + "]");
    }
}

From source file:com.owncloud.android.lib.test_project.test.SingleSessionManagerTest.java

public SingleSessionManagerTest() {
    super();//from w ww.jav  a 2  s.co  m

    Protocol pr = Protocol.getProtocol("https");
    if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
        try {
            ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
            Protocol.registerProtocol("https", new Protocol("https", psf, 443));

        } catch (GeneralSecurityException e) {
            throw new AssertionFailedError("Self-signed confident SSL context could not be loaded");
        }
    }
}

From source file:com.owncloud.android.lib.test_project.test.SimpleFactoryManagerTest.java

public SimpleFactoryManagerTest() {
    super();/*  w  w  w .jav a  2  s .  c o  m*/

    Protocol pr = Protocol.getProtocol("https");
    if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
        try {
            ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
            Protocol.registerProtocol("https", new Protocol("https", psf, 443));

        } catch (GeneralSecurityException e) {
            throw new AssertionFailedError("Self-signed confident SSL context could not be loaded");
        }
    }
}