1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package com.codebox.instance;
16
17 import java.lang.reflect.InvocationTargetException;
18
19 import mockit.Expectations;
20 import mockit.Mocked;
21 import mockit.Tested;
22
23 import org.junit.jupiter.api.Assertions;
24 import org.junit.jupiter.api.Disabled;
25 import org.junit.jupiter.api.Test;
26
27
28
29
30
31 @Disabled
32 class ClassInstanceTest {
33
34
35 @Tested
36 ClassInstance<Object> classInstance;
37
38
39 @Mocked
40 Class<Object> mockClazz;
41
42
43
44
45
46
47
48
49
50
51
52
53
54 @Test
55 void newInstanceInstantiationException()
56 throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
57 Assertions.assertNotNull(new Expectations() {
58 {
59 ClassInstanceTest.this.mockClazz.getDeclaredConstructor().newInstance();
60 this.result = new InstantiationException();
61 }
62 });
63 this.classInstance.newInstance(this.mockClazz);
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77
78 @Test
79 void newInstanceIllegalAccessException()
80 throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
81 Assertions.assertNotNull(new Expectations() {
82 {
83 ClassInstanceTest.this.mockClazz.getDeclaredConstructor().newInstance();
84 this.result = new IllegalAccessException();
85 }
86 });
87 this.classInstance.newInstance(this.mockClazz);
88 }
89
90 }