package org.camunda.bpm.engine.test.bpmn.event.error;

import static org.assertj.core.api.Assertions.assertThat;

import org.camunda.bpm.engine.delegate.BpmnError;
import org.junit.Test;

/**
 * This test asserts the constructors of the {@link BpmnError} class as this
 * is part of the public API
 */
public class BpmnErrorTest {

  /** Error code used when creating BpmnError instances */
  private static final String ERROR_CODE = "testErrorCode";

  /** Error message used when creating BpmnError instances */
  private static final String ERROR_MESSAGE = "testErrorMessage";

  /** Cause object used when creating BpmnError instances with a cause */
  private static final Throwable CAUSE = new IllegalArgumentException("causeMessage");

  @Test
  public void testCreation_ErrorCodeOnly_BpmnMessageContainsErrorCode() {
    // when
    BpmnError bpmnError = new BpmnError(ERROR_CODE);
    
    // then
    assertThat(bpmnError).hasMessage(null);
    assertThat(bpmnError.getErrorCode()).isEqualTo(ERROR_CODE);
  }

  @Test
  public void testCreation_ErrorMessagePresent_BpmnMessageContainsErrorCodeAndMessage() {
    // when
    BpmnError bpmnError = new BpmnError(ERROR_CODE, ERROR_MESSAGE);
    
    // then
    assertThat(bpmnError).hasMessage(ERROR_MESSAGE);
    assertThat(bpmnError.getErrorCode()).isEqualTo(ERROR_CODE);
  }

  @Test
  public void testCreation_ErrorCodeOnlyWithCause_BpmnMessageIsCopiedFromCause() {
    // when
    BpmnError bpmnError = new BpmnError(ERROR_CODE, CAUSE);
    
    // then
    assertThat(bpmnError)
            .hasMessage(null)
            .hasCause(CAUSE);
    assertThat(bpmnError.getErrorCode()).isEqualTo(ERROR_CODE);
  }

  @Test
  public void testCreation_ErrorMessageAndCausePresent_BpmnMessageContainsCause() {
    // when
    BpmnError bpmnError = new BpmnError(ERROR_CODE, ERROR_MESSAGE, CAUSE);
    
    // then
    assertThat(bpmnError)
            .hasMessageContaining(ERROR_MESSAGE)
            .hasCause(CAUSE);
    assertThat(bpmnError.getErrorCode()).isEqualTo(ERROR_CODE);
  }
}

@@ -1,8 +1,816 @@
+/*%0A * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH%0A * under one or more contributor license agreements. See the NOTICE file%0A * distributed with this work for additional information regarding copyright%0A * ownership. Camunda licenses this file to you under the Apache License,%0A * Version 2.0; you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package 

add missing license header