View Javadoc
1   /*
2    * Copyright 2011-2024 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.googlecode.catchexception.throwable.apis;
17  
18  import static com.googlecode.catchexception.throwable.apis.BDDCatchThrowable.when;
19  import static com.googlecode.catchexception.throwable.apis.MyThrowableCustomAssertions.caughtThrowable;
20  import static com.googlecode.catchexception.throwable.apis.MyThrowableCustomAssertions.then;
21  
22  import com.googlecode.catchexception.throwable.MyThrowable;
23  
24  import org.junit.jupiter.api.Test;
25  
26  /**
27   * Tests custom throwable assertions.
28   */
29  class BDDCustomCatchThrowableTest {
30  
31      /**
32       * Custom exception.
33       *
34       * @throws Exception
35       *             the exception
36       */
37      @Test
38      void customException() throws Exception {
39  
40          when(this::throwMyThrowable);
41  
42          then(caughtThrowable()).hasErrorCode(500);
43      }
44  
45      /**
46       * Throw my throwable.
47       */
48      private void throwMyThrowable() {
49          throw new MyThrowable(500);
50      }
51  
52  }