/
KlassTest.java
62 lines (54 loc) · 2.1 KB
/
KlassTest.java
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
package org.kohsuke.stapler.lang;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
import org.kohsuke.stapler.Function;
/**
* Contains tests for {@link Klass}.
* @author Oleg Nenashev.
*/
public class KlassTest {
@Test
public void shouldProperlyAccessJavaDeclaredMethods() throws Exception {
final Klass<Class> classInstance = Klass.java(FooClass.class);
final List<MethodRef> declaredFunctions = classInstance.getDeclaredMethods();
for (MethodRef ref : declaredFunctions) {
if ("doDynamic".equals(ref.getName())) {
//TODO: check field parameters once Stapler provides such info
return;
}
}
Assert.fail("Have not found the 'doDynamic' declared method for FooClass");
}
@Test
public void shouldProperlyAccessJavaDeclaredFields() throws Exception {
final Klass<Class> classInstance = Klass.java(FooClass.class);
final List<FieldRef> declaredFields = classInstance.getDeclaredFields();
for (FieldRef ref : declaredFields) {
if ("fooField".equals(ref.getName())) {
//TODO: check field parameters once Stapler provides such info
return;
}
}
Assert.fail("Have not found 'fooField' in the returned field list");
}
@Test
public void shouldProperlyAccessJavaDeclaredFunctions() throws Exception {
final Klass<Class> classInstance = Klass.java(FooClass.class);
final List<Function> declaredFunctions = classInstance.getFunctions();
for (Function ref : declaredFunctions) {
if ("doDynamic".equals(ref.getName())) {
//TODO: check field parameters once Stapler provides such info
return;
}
}
Assert.fail("Have not found 'doDynamic' function for FooClass");
}
private static final class FooClass {
private int fooField;
public Object doDynamic(String token) {
// Just return something potentially routable
return Integer.valueOf(0);
}
}
}