-
-
Notifications
You must be signed in to change notification settings - Fork 776
/
AdviceParameterWriteTest.java
158 lines (120 loc) · 3.57 KB
/
AdviceParameterWriteTest.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
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
149
150
151
152
153
154
155
156
157
158
package net.bytebuddy.asm;
import net.bytebuddy.ByteBuddy;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import static net.bytebuddy.matcher.ElementMatchers.named;
@RunWith(Parameterized.class)
public class AdviceParameterWriteTest {
private static final String FOO = "foo", BAR = "bar", ENTER = "enter", EXIT = "exit", exception = "exception";
private static final byte VALUE = 42;
private static final boolean BOOLEAN = true;
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{BooleanAdvice.class},
{ByteAdvice.class},
{ShortAdvice.class},
{CharacterAdvice.class},
{IntegerAdvice.class},
{LongAdvice.class},
{FloatAdvice.class},
{DoubleAdvice.class},
{ReferenceAdvice.class}
});
}
private final Class<?> type;
public AdviceParameterWriteTest(Class<?> type) {
this.type = type;
}
@Test(expected = IllegalStateException.class)
public void testIllegalAssignment() throws Exception {
new ByteBuddy()
.redefine(type)
.visit(Advice.to(type).on(named(FOO)))
.make();
}
public static class BooleanAdvice {
void foo(boolean value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) boolean value) {
value = BOOLEAN;
}
}
public static class ByteAdvice {
void foo(byte value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) byte value) {
value = VALUE;
}
}
public static class ShortAdvice {
void foo(short value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) short value) {
value = VALUE;
}
}
public static class CharacterAdvice {
void foo(char value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) char value) {
value = VALUE;
}
}
public static class IntegerAdvice {
void foo(int value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) int value) {
value = VALUE;
}
}
public static class LongAdvice {
void foo(long value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) long value) {
value = VALUE;
}
}
public static class FloatAdvice {
void foo(float value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) float value) {
value = VALUE;
}
}
public static class DoubleAdvice {
void foo(double value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) double value) {
value = VALUE;
}
}
public static class ReferenceAdvice {
void foo(Object value) {
/* empty */
}
@Advice.OnMethodEnter
public static void enter(@Advice.Argument(0) Object value) {
value = FOO;
}
}
}