Example usage for java.lang IllegalStateException getSuppressed

List of usage examples for java.lang IllegalStateException getSuppressed

Introduction

In this page you can find the example usage for java.lang IllegalStateException getSuppressed.

Prototype

public final synchronized Throwable[] getSuppressed() 

Source Link

Document

Returns an array containing all of the exceptions that were suppressed, typically by the try -with-resources statement, in order to deliver this exception.

Usage

From source file:org.elasticsearch.client.SyncResponseListenerTests.java

public void testOnSuccess() throws Exception {
    RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000);
    Response mockResponse = mockResponse();
    syncResponseListener.onSuccess(mockResponse);
    Response response = syncResponseListener.get();
    assertSame(response, mockResponse);/*w w  w .j av a2  s.c  o  m*/

    try {
        syncResponseListener.onSuccess(mockResponse);
        fail("get should have failed");
    } catch (IllegalStateException e) {
        assertEquals(e.getMessage(), "response is already set");
    }
    response = syncResponseListener.get();
    assertSame(response, mockResponse);

    RuntimeException runtimeException = new RuntimeException("test");
    syncResponseListener.onFailure(runtimeException);
    try {
        syncResponseListener.get();
        fail("get should have failed");
    } catch (IllegalStateException e) {
        assertEquals("response and exception are unexpectedly set at the same time", e.getMessage());
        assertNotNull(e.getSuppressed());
        assertEquals(1, e.getSuppressed().length);
        assertSame(runtimeException, e.getSuppressed()[0]);
    }
}

From source file:org.metaeffekt.dcc.test.ProfileCommandExecutionTest.java

@Test
public void testSimpleDeploymentInstallation() throws IOException {

    Profile profile = ProfileParser.parse(new File(SOLUTION_DIR, "dcc-test-deployment-profile.xml"));

    PropertiesHolder propertiesHolder = profile.createPropertiesHolder(true);

    profile.evaluate(propertiesHolder);// w w w  .  ja v  a  2  s  .c om

    propertiesHolder.dump();

    File targetBaseDir = new File(TARGET_BASE_DIR);
    if (!targetBaseDir.exists()) {
        targetBaseDir.mkdirs();
    }

    ExecutionContext executionContext = new ExecutionContext(
            new SSLConfiguration("target/dcc/config/dcc-shell.keystore", "DYKK8T8m9nKqBRPZ",
                    "target/dcc/config/dcc-shell.truststore", "DYKK8T8m9nKqBRPZ"));
    executionContext.setProfile(profile);
    executionContext.setSolutionDir(new File(SOLUTION_DIR));
    executionContext.setTargetBaseDir(targetBaseDir);
    executionContext.prepareForExecution();

    InitializeCommand initializeCommand = new InitializeCommand(executionContext);
    initializeCommand.execute(true, true);

    try {
        VerifyCommand verifyCommand = new VerifyCommand(executionContext);
        verifyCommand.execute(true, true);
    } catch (IllegalStateException e) {
        Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("Execution of unit-04 failed"));
    }

    InstallCommand installCommand = new InstallCommand(executionContext);
    installCommand.execute(true, true);

    ConfigureCommand configureCommand = new ConfigureCommand(executionContext);
    configureCommand.execute(true, true);

    StartCommand startCommand = new StartCommand(executionContext);
    startCommand.execute(true, true);

    try {
        StopCommand stopCommand = new StopCommand(executionContext);
        stopCommand.execute(true, true);
    } catch (BuildException e) {
    }
}