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.sourcepit.common.maven.testing.ExternalMavenTest.java

protected CommandLine newCmd(File binDir, String bat, String sh, String... arguments) {
    final CommandLine cmd;
    if (OS.isFamilyWindows() || OS.isFamilyWin9x()) {
        cmd = process.newCommandLine(new File(binDir, bat));
    } else if (OS.isFamilyUnix() || OS.isFamilyMac()) {
        cmd = process.newCommandLine("sh", new File(binDir, sh).getAbsolutePath());
    } else {/*from w w w . j av a 2s  . c  o m*/
        throw new AssertionFailedError("Os family");
    }
    cmd.addArguments(arguments);
    return cmd;
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

public String CFAPPS_IO() {
    String org = clientParams.getOrgName();
    String api = clientParams.getApiUrl();
    if (org.equals("application-platform-testing")) {
        //PWS test space/org
        return "cfapps.io";
    } else if (org.equals("pivot-kdevolder")) {
        //PEZ/*from   ww w. ja v  a  2 s. c o m*/
        return "cfapps.pez.pivotal.io";
    } else if (api.contains("api.tan.")) {
        //TAN
        return "tan.springapps.io";
    }
    throw new AssertionFailedError("unknown test environment, not sure what to expect here");
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

public String[] getExpectedDomains() {
    String org = clientParams.getOrgName();
    String api = clientParams.getApiUrl();
    if (org.equals("application-platform-testing")) {
        //PWS test space/org
        return new String[] { "cfapps.io" };
    } else if (org.equals("pivot-kdevolder")) {
        //PEZ/*from  www. j a  v a 2s.  c  om*/
        return new String[] { "cfapps.pez.pivotal.io", "pezapp.io" };
    } else if (api.contains("api.tan.")) {
        //TAN
        return new String[] { "tan.springapps.io" };
    }
    throw new AssertionFailedError("unknown test environment, not sure what to expect here");
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

public String[] getExectedBuildpacks() {
    String org = clientParams.getOrgName();
    String api = clientParams.getApiUrl();
    if (org.equals("application-platform-testing")) {
        //PWS test space/org
        return new String[] { "staticfile_buildpack", "java_buildpack", "ruby_buildpack" };
    } else if (org.equals("pivot-kdevolder")) {
        //PEZ//from ww  w .  ja va  2  s.c o  m
        return new String[] { "staticfile_buildpack", "java_buildpack_offline", "ruby_buildpack" };
    } else if (api.contains("api.tan.")) {
        //TAN
        return new String[] { "staticfile_buildpack", "java_buildpack_offline", "ruby_buildpack" };
    }
    throw new AssertionFailedError("unknown test environment, not sure what to expect here");
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

public String getExpectedSshHost() {
    String org = clientParams.getOrgName();
    String api = clientParams.getApiUrl();
    if (org.equals("application-platform-testing")) {
        //PWS//  w  w w .j a v a 2s.co  m
        return "ssh.run.pivotal.io";
    } else if (api.contains("api.tan.")) {
        //TAN
        return "ssh.tan.springapps.io";
    }
    throw new AssertionFailedError("unknown test environment, not sure what to expect here");
}

From source file:org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.java

/**
 * Runs a test via the supplied {@link TestExecutionCallback}, providing
 * support for the {@link ExpectedException @ExpectedException} and
 * {@link Repeat @Repeat} annotations.
 *
 * @param tec the test execution callback to run
 * @param testMethod the actual test method: used to retrieve the
 * {@link ExpectedException @ExpectedException} and {@link Repeat
 * @Repeat} annotations//from w  w w. j  ava  2  s  .  c o  m
 * @throws Throwable if any exception is thrown
 * @see ExpectedException
 * @see Repeat
 */
private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwable {
    ExpectedException expectedExceptionAnnotation = testMethod.getAnnotation(ExpectedException.class);
    boolean exceptionIsExpected = (expectedExceptionAnnotation != null
            && expectedExceptionAnnotation.value() != null);
    Class<? extends Throwable> expectedException = (exceptionIsExpected ? expectedExceptionAnnotation.value()
            : null);

    Repeat repeat = testMethod.getAnnotation(Repeat.class);
    int runs = ((repeat != null) && (repeat.value() > 1)) ? repeat.value() : 1;

    for (int i = 0; i < runs; i++) {
        try {
            if (runs > 1 && this.logger.isInfoEnabled()) {
                this.logger.info("Repetition " + (i + 1) + " of test " + testMethod.getName());
            }
            tec.run();
            if (exceptionIsExpected) {
                fail("Expected exception: " + expectedException.getName());
            }
        } catch (Throwable ex) {
            if (!exceptionIsExpected) {
                throw ex;
            }
            if (!expectedException.isAssignableFrom(ex.getClass())) {
                // Wrap the unexpected throwable with an explicit message.
                AssertionFailedError assertionError = new AssertionFailedError(
                        "Unexpected exception, expected <" + expectedException.getName() + "> but was <"
                                + ex.getClass().getName() + ">");
                assertionError.initCause(ex);
                throw assertionError;
            }
        }
    }
}

From source file:org.springsource.ide.eclipse.gradle.core.test.GradleTest.java

public void assertErrors(IProject project, boolean build, String... expectedRegexps) throws Exception {
    if (build) {//from  w ww  .  j a  v a  2  s .  c om
        project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
    }
    GradleClassPathContainer.waitForMarkerUpdates();
    IMarker[] problems = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
    Set<String> notSeenYet = new HashSet<String>(Arrays.asList(expectedRegexps));
    for (IMarker problem : problems) {
        if (problem.getAttribute(IMarker.SEVERITY, 0) >= IMarker.SEVERITY_ERROR) {
            checkExpectedExpectedError(notSeenYet, expectedRegexps, markerMessage(problem));
        }
    }
    if (notSeenYet.isEmpty()) {
        //ok
    } else {
        StringBuilder error = new StringBuilder("Some expected errors where not found:\n");
        for (String string : notSeenYet) {
            error.append(string + "\n");
        }
        throw new AssertionFailedError(error.toString());
    }
}

From source file:org.xwiki.filter.test.internal.ZIPFileAssertComparator.java

/**
 * Asserts that two ZIP files are equal. If they are not, an {@link AssertionError} without a message is thrown.
 *//*www. java2  s .c o m*/
public void assertEquals(String message, File expected, File actual) {
    Assert.assertNotNull(expected);
    Assert.assertNotNull(actual);

    Assert.assertTrue("Expected file does not exist [" + expected.getAbsolutePath() + "]", expected.exists());
    Assert.assertTrue("Actual file does not exist [" + actual.getAbsolutePath() + "]", actual.exists());

    Assert.assertTrue("Expected file not readable", expected.canRead());
    Assert.assertTrue("Actual file not readable", actual.canRead());

    try {
        Map<String, byte[]> expectedMap = unzip(expected);
        Map<String, byte[]> actualMap = unzip(actual);

        for (Map.Entry<String, byte[]> expectedEntry : expectedMap.entrySet()) {
            byte[] actualContent = actualMap.get(expectedEntry.getKey());

            Assert.assertNotNull("Entry [" + expectedEntry.getKey() + "] not present", actualContent);

            FileAssertComparator fileAssertComparator = FileAssert.getComparator(expectedEntry.getKey());

            fileAssertComparator.assertEquals("Entry [" + expectedEntry.getKey() + "] has different content",
                    expectedEntry.getValue(), actualContent);
        }

        Assert.assertEquals("Too much entries", expectedMap.size(), actualMap.size());
    } catch (IOException e) {
        throw new AssertionFailedError(e.toString());
    }
}

From source file:servletunit.frame2.MockFrame2TestCase.java

/**
 * A check that every method should run to ensure that the base class setUp
 * method has been called.//from  w  w w  . j av a2s .c  o  m
 */

private void confirmSetup() {
    if (!this.isInitialized) {
        throw new AssertionFailedError(
                "You are overriding the setUp() method without calling super.setUp().  You must call the superclass setUp() method in your TestCase subclass to ensure proper initialization."); //$NON-NLS-1$
    }
}

From source file:servletunit.frame2.MockFrame2TestCase.java

/**
 * Sets the location of the web.xml configuration file to be used to set up
 * the servlet context and configuration for this test. This method supports
 * both init-param and context-param tags, setting the ServletConfig and
 * ServletContext appropriately. This method can take either an absolute
 * path, or a relative path. If an absolute path is supplied, the
 * configuration file will be loaded from the underlying filesystem;
 * otherwise, the ServletContext loader will be used.
 *///www.  j  av  a  2  s. co  m
public void setServletConfigFile(String pathname) {
    confirmSetup();

    // pull in the appropriate parts of the
    // web.xml file -- first the init-parameters
    Digester digester = new Digester();
    digester.push(this.config);
    digester.setValidating(false);
    digester.addCallMethod("web-app/servlet/init-param", //$NON-NLS-1$
            "setInitParameter", 2); //$NON-NLS-1$
    digester.addCallParam("web-app/servlet/init-param/param-name", 0); //$NON-NLS-1$
    digester.addCallParam("web-app/servlet/init-param/param-value", 1); //$NON-NLS-1$
    try {
        InputStream input = this.context.getResourceAsStream(pathname);
        if (input == null)
            throw new AssertionFailedError("Invalid pathname: " + pathname); //$NON-NLS-1$
        digester.parse(input);
        input.close();
    } catch (Exception e) {
        throw new AssertionFailedError("Received an exception while loading web.xml - " //$NON-NLS-1$
                + e.getClass() + " : " + e.getMessage()); //$NON-NLS-1$
    }

    // now the context parameters..
    digester = new Digester();
    digester.setValidating(false);
    digester.push(this.context);
    digester.addCallMethod("web-app/context-param", "setInitParameter", 2); //$NON-NLS-1$ //$NON-NLS-2$
    digester.addCallParam("web-app/context-param/param-name", 0); //$NON-NLS-1$
    digester.addCallParam("web-app/context-param/param-value", 1); //$NON-NLS-1$
    try {
        InputStream input = this.context.getResourceAsStream(pathname);
        if (input == null)
            throw new AssertionFailedError("Invalid pathname: " + pathname); //$NON-NLS-1$
        digester.parse(input);
        input.close();
    } catch (Exception e) {
        throw new AssertionFailedError("Received an exception while loading web.xml - " //$NON-NLS-1$
                + e.getClass() + " : " + e.getMessage()); //$NON-NLS-1$
    }
}