-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestReflectionProxy.java
More file actions
55 lines (38 loc) · 1.46 KB
/
TestReflectionProxy.java
File metadata and controls
55 lines (38 loc) · 1.46 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
package xyz.ericlamm.toolkits.reflectionproxy;
import org.junit.jupiter.api.Test;
public class TestReflectionProxy {
private final ProxyPrepareManager prepareManager = ReflectionProxy.newPrepareManager();
@Test
void testSecretManager() throws Exception {
var reflectionProxy = ReflectionProxy
.builder(prepareManager)
.prepare(HackedSecretManager.class)
.build();
var manager1 = new SecretManager("this is a secret");
var proxy1 = reflectionProxy.createProxyForInstance(HackedSecretManager.class, manager1);
var proxy2 = reflectionProxy.createProxy(HackedSecretManager.class);
System.out.println("proxy1: " + proxy1.getSecretName());
System.out.println("proxy2: " + proxy2.getSecretName());
proxy1.printSecret();
proxy2.printSecret();
proxy1.setSecretName("this is a new secret");
proxy2.setSecretName("this is a new default secret");
proxy1.printSecret();
proxy2.printSecret();
proxy1.shuffSecretName();
proxy2.shuffSecretName();
System.out.println("proxy1: " + proxy1.getSecretName());
System.out.println("proxy2: " + proxy2.getSecretName());
}
@Test
void testRootManager() throws Exception {
var reflectionProxy = ReflectionProxy
.builder(prepareManager)
.prepare(HackedRootManager.class)
.prepare(HackedSecretManager.class)
.build();
var rootProxy = reflectionProxy.createProxy(HackedRootManager.class);
HackedSecretManager secretManager = rootProxy.getSecretManager();
secretManager.printSecret();
}
}