Example usage for java.lang AssertionError getMessage

List of usage examples for java.lang AssertionError getMessage

Introduction

In this page you can find the example usage for java.lang AssertionError getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.emarsys.dyson.DysonStorage.java

/**
 * <p>/*from w  ww . j ava 2s  .  co m*/
 * initializes this storage instance after it's creation.
 * </p><p>
 * if this methods is redefined in subclasses then it should
 * call it's super implementation as first statement unless
 * there's a good reason not to do so.
 * </p>
 * 
 * @throws IllegalStateException
 */
protected void checkInitialization() throws IllegalStateException {
    try {
        Assertions.assertNotEmpty(this.incomingDirName);
        Assertions.assertNotEmpty(this.processedDirName);
        Assertions.assertNotEmpty(this.mailFileSuffix);
        Assertions.assertNotEmpty(this.mailPartialFileSuffix);
        Assertions.assertNotNull(this.namingScheme);
    }
    //TODO refactor "not empty checks" in order to omit this exception wrapping
    catch (AssertionError ae) {
        throw new IllegalStateException("" + ae.getMessage(), ae);
    }
}

From source file:org.marketcetera.util.test.EqualityAssertTest.java

@Test
public void arrayIncorrect() {
    try {//w w w. ja v  a  2s  .co m
        assertEquality(new Correct(0), 0, new Object[] { new Correct(1), new Correct(0), new Correct(2) });
    } catch (AssertionError ex) {
        assertEquals("'I am 0' unequal to 'I am 1'", ex.getMessage());
        return;
    }
    fail();
}

From source file:org.marketcetera.util.test.EqualityAssertTest.java

@Test
public void copyUnequals() {
    try {//from   w w  w . ja  v a 2  s .  com
        assertEquality(new CopyUnequals(), new CopyUnequals());
    } catch (AssertionError ex) {
        assertEquals("'I am copy' unequal to 'I am copy'", ex.getMessage());
        return;
    }
    fail();
}

From source file:org.marketcetera.util.test.EqualityAssertTest.java

@Test
public void message() {
    try {/*w ww .  ja  v a  2s .c om*/
        assertEquality("Right now,", new SelfUnequals(), new SelfUnequals());
    } catch (AssertionError ex) {
        assertEquals("Right now, 'I am self' unequal to self", ex.getMessage());
        return;
    }
    fail();
}

From source file:org.marketcetera.util.test.EqualityAssertTest.java

@Test
public void arrayMessage() {
    try {/*from  www. j  av  a  2s . c o m*/
        assertEquality("Right now,", new Correct(0), 0,
                new Object[] { new Correct(1), new Correct(0), new Correct(2) });
    } catch (AssertionError ex) {
        assertEquals("Right now, 'I am 0' unequal to 'I am 1'", ex.getMessage());
        return;
    }
    fail();
}

From source file:org.marketcetera.util.test.EqualityAssertTest.java

@Test
public void badHashCode() {
    try {// w w  w . jav a2 s . co  m
        assertEquality(new BadHashCode(0), new BadHashCode(0));
    } catch (AssertionError ex) {
        assertEquals("'I am 0' hash code unequal to copy's 'I am 0'", ex.getMessage());
        return;
    }
    fail();
}

From source file:net.javacrumbs.jsonunit.spring.ExampleControllerTest.java

@Test
public void isStringEqualToShouldFailOnNumber() throws Exception {
    try {/*from  w w  w  .  ja  v  a  2  s  . com*/
        exec().andExpect(json().node("result.array[0]").isStringEqualTo("1"));
        failIfNoException();
    } catch (AssertionError e) {
        assertEquals("Node \"result.array[0]\" is not a string. The actual value is '1'.", e.getMessage());
    }
}

From source file:com.canoo.webtest.extension.ScriptStep.java

/**
 * Perform the step's actual work.//from  www .j  a  va  2 s .  co  m
 *
 * @throws Exception if a problem occurred
 */
public void doExecute() throws Exception {
    final ResetScriptRunner runner; // delegate pattern
    final Context context = getContext();
    if (context.getRunner() == null) {
        runner = new ResetScriptRunner();
        runner.setLanguage(getLanguage());
        context.setRunner(runner);
        LOG.debug("Creating new Script Runner with language: " + fLanguage);
    } else {
        runner = context.getRunner();
        runner.reset();
    }
    buildScript();
    getProject().addReference("step", this);
    if (context.getCurrentResponse() == null) {
        LOG.warn("No response found. Previous invoke missing? Related scripting variables not created");
    } else {
        setupResponseScriptingVariables(context);
    }

    try {
        executeByRunner(runner, getProject().replaceProperties(fScriptText), this, getProject());
        // languages like groovy can throw assert errors which are useful to fail test
        // but what about an assert in groovy's implementation that has failed - this should
        // probably be configurable to potentially throw StepExecutionError
    } catch (AssertionError ae) {
        final String msg = "Assertion error during scriptStep: " + ae.getMessage();
        LOG.debug(msg, ae);
        throw new StepFailedException(msg, this);
    } catch (BuildException be) {
        LOG.debug(be.getMessage(), be);
        throw new StepExecutionException("Error invoking script: " + be.getMessage(), this);
    } finally {
        if (!isKeep()) {
            context.setRunner(null);
        }
    }
}

From source file:com.netflix.curator.framework.recipes.queue.TestDistributedPriorityQueue.java

@Test
public void testSimple() throws Exception {
    List<Integer> nums = new ArrayList<Integer>();

    Timing timing = new Timing();
    DistributedPriorityQueue<Integer> queue = null;
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(),
            timing.connection(), new RetryOneTime(1));
    client.start();/*from   w  ww. j a v a 2 s. c  o m*/
    try {
        final CountDownLatch hasConsumedLatch = new CountDownLatch(1);
        final CountDownLatch okToConsumeLatch = new CountDownLatch(1);
        BlockingQueueConsumer<Integer> consumer = new BlockingQueueConsumer<Integer>(
                Mockito.mock(ConnectionStateListener.class)) {
            @Override
            public void consumeMessage(Integer message) throws Exception {
                hasConsumedLatch.countDown();
                okToConsumeLatch.await();
                super.consumeMessage(message);
            }
        };
        queue = QueueBuilder.builder(client, consumer, new IntSerializer(), "/test").buildPriorityQueue(0);
        queue.start();

        nums.add(Integer.MIN_VALUE);
        queue.put(Integer.MIN_VALUE, Integer.MIN_VALUE); // the queue background thread will be blocking with the first item - make sure it's the lowest value
        Assert.assertTrue(timing.awaitLatch(hasConsumedLatch));

        Random random = new Random();
        for (int i = 0; i < 100; ++i) {
            int priority = random.nextInt();
            nums.add(priority);
            queue.put(priority, priority);
        }

        while (queue.getCache().getData().children.size() < (nums.size() - 1)) // -1 because the first message has already been consumed
        {
            timing.sleepABit(); // wait for the cache to catch up
        }
        okToConsumeLatch.countDown();

        assertOrdering(consumer, nums.size());
    } catch (AssertionError e) {
        StringBuilder message = new StringBuilder(e.getMessage());
        for (int i : nums) {
            message.append(i).append("\t").append(DistributedPriorityQueue.priorityToString(i)).append("\n");
        }
        Assert.fail(message.toString());
    } finally {
        IOUtils.closeQuietly(queue);
        IOUtils.closeQuietly(client);
    }
}

From source file:net.javacrumbs.jsonunit.spring.ExampleControllerTest.java

@Test
public void isStringShouldFailOnArray() throws Exception {
    try {/*from w  w  w .j  a v  a  2 s.  co  m*/
        exec().andExpect(json().node("result.array").isString());
        failIfNoException();
    } catch (AssertionError e) {
        assertEquals("Node \"result.array\" is not a string. The actual value is '[1,2,3]'.", e.getMessage());
    }
}