1 /*
2 * Copyright 2011-2025 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 when(this::throwMyThrowable);
40 then(caughtThrowable()).hasErrorCode(500);
41 }
42
43 /**
44 * Throw my throwable.
45 */
46 private void throwMyThrowable() {
47 throw new MyThrowable(500);
48 }
49
50 }