Example usage for java.lang AssertionError printStackTrace

List of usage examples for java.lang AssertionError printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.kalypso.commons.junit.FileAssert.java

/**
 * Asserts that the contents of two files is equal.
 *///from www.j  a v a  2  s .  co m
public static void assertFileContentEquals(final File expected, final File actual) {
    try {
        final List<String> actualLines = FileUtils.readLines(actual, (Charset) null);
        final List<String> expectedLines = FileUtils.readLines(expected, (Charset) null);

        final Iterator<String> actualIt = actualLines.iterator();
        final Iterator<String> expectedIt = expectedLines.iterator();

        int count = 0;
        while (expectedIt.hasNext() && actualIt.hasNext()) {
            count++;

            final Object expectedLine = expectedIt.next();
            final Object actualLine = actualIt.next();

            try {
                Assert.assertEquals(expectedLine, actualLine);
            } catch (final AssertionError e) {
                final String msg = String.format("Line %d: %s", count, e.getLocalizedMessage()); //$NON-NLS-1$
                fail(msg);
            }
        }

        assertIteratorIsEmpty("Actual file is longer than expected: ", actualIt); //$NON-NLS-1$
        assertIteratorIsEmpty("Expected file is longer than actual: ", expectedIt); //$NON-NLS-1$
    } catch (final IOException e) {
        e.printStackTrace();
        Assert.fail("Failed to access file: " + e.getLocalizedMessage()); //$NON-NLS-1$
    }
}

From source file:org.asamk.signal.Main.java

private static void handleAssertionError(AssertionError e) {
    System.err.println("Failed to send/receive message (Assertion): " + e.getMessage());
    e.printStackTrace();
    System.err.println(//from w  ww  .j  a v  a 2  s . co  m
            "If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README");
    System.exit(1);
}

From source file:com.avanza.ymer.YmerConverterTestBaseTest.java

private void assertFails(TestRun testRun) {
    boolean failed = false;
    try {/*from w w w .j  av a 2 s.  c  o  m*/
        testRun.run();
    } catch (AssertionError e) {
        failed = true;
    } catch (Exception e) {
        e.printStackTrace();
        failed = true;
    }
    assertTrue("Expected test to fail", failed);
}

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformIllumination.java

/**
 * This method is called by an illumination source when its state has changed.
 * /*from   w  ww  .j a va 2  s . co  m*/
 * @param data The message that is passed from the illumination source.
 */
@Override
public void update(Object data) throws WrongMessageTypeException {
    if (data == null) {
        // No data reported by the Observable.
        return;
    }
    try {
        Message msg = (Message) data;
        assert (msg.getType() == MessageType.LASER_POWER_CHANGE);
        double power = msg.toJson().getAsJsonObject().get("power").getAsDouble();
        this.setPower(power);
    } catch (AssertionError ex) {
        String err = "The message from the illumination source was not " + "the expected type.";
        LOGGER.log(Level.WARNING, err);
        throw new WrongMessageTypeException(err);
    } catch (Exception ex) {
        String err = "Could not coerce the illumination source message " + "into a known message type.";
        LOGGER.log(Level.WARNING, err);
        ex.printStackTrace();
    }
}

From source file:com.linkbubble.ui.BubbleDraggable.java

private void onAnimComplete() {
    try {/*from  ww w . j a  v  a  2s. c  o  m*/
        // Sometimes there are two calls to animation, we will handle that later
        Util.Assert(mAnimActive, "mAnimActive=" + mAnimActive);
    } catch (AssertionError exc) {
        exc.printStackTrace();
    }
    mAnimActive = false;
}

From source file:com.linkbubble.ui.BubbleDraggable.java

public void setTargetPos(int xp, int yp, float t, DraggableHelper.AnimationType type, boolean startDelay,
        DraggableHelper.AnimationEventListener listener) {
    try {/* w  ww .j a v a2 s  .c  om*/
        Util.Assert(!mAnimActive, "mAnimActive:" + mAnimActive);
    } catch (AssertionError e) {
        mDraggableHelper.cancelAnimation();
        e.printStackTrace();
    }
    //Util.Assert(t > 0.0f, "t:" + t);      // Don't think this happens anymore - just to catch if it does happen and investigate why.
    mAnimActive = listener != null;
    if (!startDelay) {
        mDraggableHelper.setTargetPos(xp, yp, t, type, listener);
    } else {
        new SetTargetPosWithDelay(xp, yp, t, type, listener).execute();
    }
}

From source file:org.apache.hadoop.yarn.server.nodemanager.TestNodeManagerResync.java

@Test
public void testNMSentContainerStatusOnResync() throws Exception {
    final ContainerStatus testCompleteContainer = TestNodeStatusUpdater.createContainerStatus(2,
            ContainerState.COMPLETE);//from w w w  . ja  v a2  s.  c  om
    final Container container = TestNodeStatusUpdater.getMockContainer(testCompleteContainer);
    NMContainerStatus report = createNMContainerStatus(2, ContainerState.COMPLETE);
    when(container.getNMContainerStatus()).thenReturn(report);
    NodeManager nm = new NodeManager() {
        int registerCount = 0;

        @Override
        protected NodeStatusUpdater createNodeStatusUpdater(Context context, Dispatcher dispatcher,
                NodeHealthCheckerService healthChecker) {
            return new TestNodeStatusUpdaterResync(context, dispatcher, healthChecker, metrics) {
                @Override
                protected ResourceTracker createResourceTracker() {
                    return new MockResourceTracker() {
                        @Override
                        public RegisterNodeManagerResponse registerNodeManager(
                                RegisterNodeManagerRequest request) throws YarnException, IOException {
                            if (registerCount == 0) {
                                // first register, no containers info.
                                try {
                                    Assert.assertEquals(0, request.getNMContainerStatuses().size());
                                } catch (AssertionError error) {
                                    error.printStackTrace();
                                    assertionFailedInThread.set(true);
                                }
                                // put the completed container into the context
                                getNMContext().getContainers().put(testCompleteContainer.getContainerId(),
                                        container);
                                getNMContext().getApplications().put(testCompleteContainer.getContainerId()
                                        .getApplicationAttemptId().getApplicationId(), mock(Application.class));
                            } else {
                                // second register contains the completed container info.
                                List<NMContainerStatus> statuses = request.getNMContainerStatuses();
                                try {
                                    Assert.assertEquals(1, statuses.size());
                                    Assert.assertEquals(testCompleteContainer.getContainerId(),
                                            statuses.get(0).getContainerId());
                                } catch (AssertionError error) {
                                    error.printStackTrace();
                                    assertionFailedInThread.set(true);
                                }
                            }
                            registerCount++;
                            return super.registerNodeManager(request);
                        }

                        @Override
                        public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request) {
                            // first heartBeat contains the completed container info
                            List<ContainerStatus> statuses = request.getNodeStatus().getContainersStatuses();
                            try {
                                Assert.assertEquals(1, statuses.size());
                                Assert.assertEquals(testCompleteContainer.getContainerId(),
                                        statuses.get(0).getContainerId());
                            } catch (AssertionError error) {
                                error.printStackTrace();
                                assertionFailedInThread.set(true);
                            }

                            // notify RESYNC on first heartbeat.
                            return YarnServerBuilderUtils.newNodeHeartbeatResponse(1, NodeAction.RESYNC, null,
                                    null, null, null, 1000L);
                        }
                    };
                }
            };
        }
    };
    YarnConfiguration conf = createNMConfig();
    nm.init(conf);
    nm.start();

    try {
        syncBarrier.await();
    } catch (BrokenBarrierException e) {
    }
    Assert.assertFalse(assertionFailedInThread.get());
    nm.stop();
}

From source file:com.gatf.executor.validator.ResponseValidator.java

public void validate(Response response, TestCase testCase, TestCaseReport testCaseReport,
        AcceptanceTestContext context) {
    try {//w w  w . j  a v a 2 s . co  m
        Object intObj = getInternalObject(testCaseReport);
        if (intObj != null && testCase.getAexpectedNodes() != null && !testCase.getAexpectedNodes().isEmpty()) {
            for (String node : testCase.getAexpectedNodes()) {
                List<String> nodeProps = getNodeProperties(node);

                String nodeVal = null;
                if (nodeProps.size() == 1 || !hasValidationFunction(nodeProps.get(0))) {
                    nodeVal = getNodeValue(intObj, nodeProps.get(0));
                    Assert.assertNotNull("Expected Node value for " + nodeProps.get(0) + " is null", nodeVal);
                }
                if (nodeProps.size() > 1) {
                    String lhs = nodeProps.get(0);
                    String lhsv = nodeVal;
                    String oper = nodeProps.size() > 2 ? nodeProps.get(1) : "==";
                    String rhsv = nodeProps.get(nodeProps.size() - 1);
                    doNodeLevelValidation(lhs, lhsv, oper, rhsv, context, testCase, testCaseReport);
                }
            }
        }

        if (testCase.getRepeatScenarios() == null && testCase.getRepeatScenarioProviderName() == null) {
            validateLogicalConditions(testCase, context, null);
        }

        extractWorkflowVariables(testCase, testCaseReport, intObj, context);

        List<Cookie> cookies = response.getCookies();
        context.getWorkflowContextHandler().storeCookies(testCase, cookies);

        boolean authEnabled = testCase.isServerApiAuth()
                ? context.getGatfExecutorConfig().isServerLogsApiAuthEnabled()
                : context.getGatfExecutorConfig().isAuthEnabled();
        String authUrl = testCase.isServerApiAuth() ? testCase.getUrl()
                : context.getGatfExecutorConfig().getAuthUrl();
        String[] authExtractAuthParams = testCase.isServerApiAuth()
                ? context.getGatfExecutorConfig().getServerApiAuthExtractAuthParams()
                : context.getGatfExecutorConfig().getAuthExtractAuthParams();

        if (authEnabled && authUrl.equals(testCase.getUrl())) {
            String identifier = null;
            String authext = "";
            if (authExtractAuthParams[1].equalsIgnoreCase("cookie")) {
                authext = "cookie ";
                for (Cookie cookie : cookies) {
                    if (authExtractAuthParams[0].equals(cookie.getName())) {
                        identifier = cookie.getValue();
                        break;
                    }
                }
            } else if (authExtractAuthParams[1].equalsIgnoreCase("header")) {
                authext = "header ";
                identifier = response.getHeader(authExtractAuthParams[0]);
            } else {
                authext = "response-content ";
                identifier = getNodeValue(intObj, authExtractAuthParams[0]);
            }
            Assert.assertNotNull(
                    "Authentication token not found for " + authext + "(" + authExtractAuthParams[0] + ")",
                    identifier);
            context.setSessionIdentifier(identifier, testCase);
            context.getWorkflowContextHandler().getSuiteWorkflowContext(testCase).put(authExtractAuthParams[2],
                    identifier);
            Assert.assertNotNull("Authentication token is null", context.getSessionIdentifier(testCase));
        }
        testCaseReport.setStatus(TestStatus.Success.status);
    } catch (AssertionError e) {
        testCaseReport.setStatus(TestStatus.Failed.status);
        testCaseReport.setFailureReason(TestFailureReason.NodeValidationFailed.status);
        testCaseReport.setError(e.getMessage());
        testCaseReport.setErrorText(ExceptionUtils.getStackTrace(e));
        if (e.getMessage() == null && testCaseReport.getErrorText() != null
                && testCaseReport.getErrorText().indexOf("\n") != -1) {
            testCaseReport.setError(
                    testCaseReport.getErrorText().substring(0, testCaseReport.getErrorText().indexOf("\n")));
        }
        e.printStackTrace();
    } catch (Throwable e) {
        testCaseReport.setStatus(TestStatus.Failed.status);
        testCaseReport.setFailureReason(TestFailureReason.Exception.status);
        testCaseReport.setError(e.getMessage());
        testCaseReport.setErrorText(ExceptionUtils.getStackTrace(e));
        if (e.getMessage() == null && testCaseReport.getErrorText() != null
                && testCaseReport.getErrorText().indexOf("\n") != -1) {
            testCaseReport.setError(
                    testCaseReport.getErrorText().substring(0, testCaseReport.getErrorText().indexOf("\n")));
        }
        e.printStackTrace();
    }
}