View Javadoc
1   /*
2    * SPDX-License-Identifier: Apache-2.0
3    * See LICENSE file for details.
4    *
5    * Copyright 2012-2026 hazendaz
6    *
7    * Portions of initial baseline code (getter/setter test) by Rob Dawson (CodeBox)
8    */
9   package com.codebox.instance;
10  
11  import java.lang.reflect.Constructor;
12  import java.lang.reflect.InvocationTargetException;
13  
14  import org.junit.jupiter.api.Assertions;
15  import org.junit.jupiter.api.Disabled;
16  import org.junit.jupiter.api.Test;
17  import org.junit.jupiter.api.extension.ExtendWith;
18  import org.mockito.InjectMocks;
19  import org.mockito.Mock;
20  import org.mockito.Mockito;
21  import org.mockito.junit.jupiter.MockitoExtension;
22  
23  /**
24   * The Class ConstructorInstanceTest.
25   */
26  // TODO 2025-06-29 JWL Class is not mockable
27  @Disabled
28  @ExtendWith(MockitoExtension.class)
29  class ConstructorInstanceTest {
30  
31      /** The constructor instance. */
32      @InjectMocks
33      ConstructorInstance constructorInstance;
34  
35      @Mock
36      Constructor<?> mockConstructor;
37  
38      /**
39       * New instance instantiation exception.
40       *
41       * @throws InstantiationException
42       *             the instantiation exception
43       * @throws IllegalAccessException
44       *             the illegal access exception
45       * @throws InvocationTargetException
46       *             the invocation target exception
47       */
48      @Test
49      void newInstanceInstantiationException()
50              throws InstantiationException, IllegalAccessException, InvocationTargetException {
51          Mockito.when(mockConstructor.newInstance()).thenThrow(new InstantiationException());
52  
53          Assertions.assertThrows(InstantiationException.class, () -> ConstructorInstance.newInstance(mockConstructor));
54      }
55  
56      /**
57       * New instance illegal access exception.
58       *
59       * @throws InstantiationException
60       *             the instantiation exception
61       * @throws IllegalAccessException
62       *             the illegal access exception
63       * @throws InvocationTargetException
64       *             the invocation target exception
65       */
66      @Test
67      void newInstanceIllegalAccessException()
68              throws InstantiationException, IllegalAccessException, InvocationTargetException {
69          Mockito.when(mockConstructor.newInstance()).thenThrow(new IllegalAccessException());
70  
71          Assertions.assertThrows(IllegalAccessException.class, () -> ConstructorInstance.newInstance(mockConstructor));
72      }
73  
74      /**
75       * New instance invocation target exception.
76       *
77       * @throws InstantiationException
78       *             the instantiation exception
79       * @throws IllegalAccessException
80       *             the illegal access exception
81       * @throws InvocationTargetException
82       *             the invocation target exception
83       */
84      @Test
85      void newInstanceInvocationTargetException()
86              throws InstantiationException, IllegalAccessException, InvocationTargetException {
87          Mockito.when(mockConstructor.newInstance()).thenThrow(new InvocationTargetException(new Exception()));
88  
89          Assertions.assertThrows(InvocationTargetException.class,
90                  () -> ConstructorInstance.newInstance(mockConstructor));
91      }
92  
93  }