-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflectionTests.java
More file actions
148 lines (125 loc) · 3.81 KB
/
ReflectionTests.java
File metadata and controls
148 lines (125 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import static org.junit.Assert.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ReflectionTests
{
Inspector sherlock;
@Before
public void setUp() throws Exception
{
sherlock = new Inspector();
}
@After
public void tearDown() throws Exception
{
}
@Test
public void getNameTest() throws IllegalArgumentException, IllegalAccessException
{
sherlock.inspect(new ClassA(), false);
assertEquals("ClassA" ,sherlock.getDeclaringClass());
Object obj = new ClassB[12];
sherlock.inspect(new ClassB[12], false);
assertEquals(obj.getClass().getName(), sherlock.getDeclaringClass());
}
@Test
public void getSuperTest() throws Exception
{
sherlock.inspect(new ClassA(), false);
assertEquals("java.lang.Object", sherlock.getSuper());
sherlock.inspect(new ClassB(), false);
assertEquals("ClassC", sherlock.getSuper());
sherlock.inspect(new ClassB[12], false);
assertEquals("java.lang.Object", sherlock.getSuper());
}
@Test
public void getInterfaceTest() throws IllegalArgumentException, IllegalAccessException
{
sherlock.inspect(new ClassA(), false);
String[] expected = new String[2];
expected [0] = "java.io.Serializable";
expected [1] = "java.lang.Runnable";
Class<?>[] intermediate = sherlock.getInterfaces();
String[] actual = new String[intermediate.length];
assertEquals(expected.length,actual.length);
for (int x = 0; x < intermediate.length; x++)
{
actual[x] = intermediate[x].getName();
}
for (int x = 0; x < actual.length; x++)
{
assertEquals(expected[x], actual[x]);
}
}
@Test
public void getInterfaceTestTwo() throws IllegalArgumentException, IllegalAccessException
{
sherlock.inspect(new ClassC(), false);
String[] expected = new String[1];
expected [0] = "InterfaceA";
Class<?>[] intermediate = sherlock.getInterfaces();
String[] actual = new String[intermediate.length];
assertEquals(expected.length,actual.length);
for (int x = 0; x < intermediate.length; x++)
{
actual[x] = intermediate[x].getName();
}
for (int x = 0; x < actual.length; x++)
{
assertEquals(expected[x], actual[x]);
}
}
@Test
public void getMethodsTest() throws Exception
{
sherlock.inspect(new ClassB(), false);
String[] expected = new String[15];
expected [0] = "run";
expected [1] = "toString";
expected [2] = "func3";
expected [3] = "func2";
expected [4] = "func1";
expected [5] = "func0";
expected [6] = "getVal3";
expected [7] = "wait";
expected [8] = "wait";
expected [9] = "equals";
expected [10] = "notify";
expected [11] = "notifyAll";
expected [12] = "getClass";
expected [13] = "wait";
expected [14] = "hashCode";
Method[] intermediate = sherlock.getMethods();
String[] actual = new String[intermediate.length];
assertEquals(expected.length,actual.length);
for (int x = 0; x < intermediate.length; x++)
{
actual[x] = intermediate[x].getName();
}
Arrays.sort(expected);
Arrays.sort(actual);
assertArrayEquals(expected, actual);
}
@Test
public void getConstructorsTest() throws IllegalArgumentException, IllegalAccessException
{
sherlock.inspect(new ClassA(), false);
String[] expected = new String[2];
expected[0] = "ClassA";
expected[1] = "ClassA";
Constructor[] intermediate = sherlock.getConstructors();
String[] actual = new String[intermediate.length];
assertEquals(expected.length,actual.length);
for (int x = 0; x < intermediate.length; x++)
{
actual[x] = intermediate[x].getName();
}
//Arrays.sort(expected);
Arrays.sort(actual);
assertArrayEquals(expected, actual);
}
}