View Javadoc
1   /*
2    * MIT License
3    * Copyright (c) 2006-2025 JMockit developers
4    * See LICENSE file for full license text.
5    */
6   package mockit.internal.reflection;
7   
8   import static org.junit.jupiter.api.Assertions.assertThrows;
9   
10  import java.io.IOException;
11  
12  import org.junit.jupiter.api.Test;
13  
14  final class ThrowOfCheckedExceptionTest {
15  
16      @Test
17      void doThrowThrowsCheckedException() {
18          // ThrowOfCheckedException.doThrow should throw the given checked exception
19          assertThrows(IOException.class, () -> {
20              try {
21                  ThrowOfCheckedException.doThrow(new IOException("test checked exception"));
22              } catch (Exception e) {
23                  if (e instanceof IOException) {
24                      throw (IOException) e;
25                  }
26                  throw e;
27              }
28          });
29      }
30  
31      @Test
32      void doThrowWithRuntimeExceptionSubclass() {
33          // Test with a non-runtime checked exception
34          assertThrows(Exception.class, () -> ThrowOfCheckedException.doThrow(new Exception("generic")));
35      }
36  }