jaroslav@355
|
1 |
/**
|
jaroslav@355
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@1787
|
3 |
* Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@355
|
4 |
*
|
jaroslav@355
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@355
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@355
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@355
|
8 |
*
|
jaroslav@355
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@355
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@355
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@355
|
12 |
* GNU General Public License for more details.
|
jaroslav@355
|
13 |
*
|
jaroslav@355
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@355
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@355
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@355
|
17 |
*/
|
jaroslav@355
|
18 |
package org.apidesign.bck2brwsr.tck;
|
jaroslav@355
|
19 |
|
jaroslav@1378
|
20 |
import java.lang.reflect.InvocationHandler;
|
jaroslav@392
|
21 |
import java.lang.reflect.Method;
|
jaroslav@1376
|
22 |
import java.lang.reflect.Proxy;
|
jaroslav@355
|
23 |
import org.apidesign.bck2brwsr.vmtest.Compare;
|
jaroslav@355
|
24 |
import org.apidesign.bck2brwsr.vmtest.VMTest;
|
jaroslav@355
|
25 |
import org.testng.annotations.Factory;
|
jaroslav@355
|
26 |
|
jaroslav@355
|
27 |
/**
|
jaroslav@355
|
28 |
*
|
jaroslav@355
|
29 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@355
|
30 |
*/
|
jaroslav@1378
|
31 |
public class ProxyTest {
|
jaroslav@1378
|
32 |
@Compare public String generateAnnotation() throws Exception {
|
jaroslav@1378
|
33 |
class InvHandler implements InvocationHandler {
|
jaroslav@1378
|
34 |
@Override
|
jaroslav@1378
|
35 |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
jaroslav@1378
|
36 |
return "Joe Hacker";
|
jaroslav@1378
|
37 |
}
|
jaroslav@1378
|
38 |
}
|
jaroslav@1378
|
39 |
Anno anno = (Anno) Proxy.newProxyInstance(
|
jaroslav@1378
|
40 |
Anno.class.getClassLoader(),
|
jaroslav@1378
|
41 |
new Class[] { Anno.class },
|
jaroslav@1378
|
42 |
new InvHandler()
|
jaroslav@1378
|
43 |
);
|
jaroslav@1378
|
44 |
return anno.name();
|
jaroslav@1378
|
45 |
}
|
jaroslav@1378
|
46 |
|
jaroslav@1378
|
47 |
@Compare public int getPrimitiveType() throws Exception {
|
jaroslav@1378
|
48 |
class InvHandler implements InvocationHandler {
|
jaroslav@1378
|
49 |
@Override
|
jaroslav@1378
|
50 |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
jaroslav@1378
|
51 |
return 40;
|
jaroslav@1378
|
52 |
}
|
jaroslav@1378
|
53 |
}
|
jaroslav@1378
|
54 |
Anno anno = (Anno) Proxy.newProxyInstance(
|
jaroslav@1378
|
55 |
Anno.class.getClassLoader(),
|
jaroslav@1378
|
56 |
new Class[] { Anno.class },
|
jaroslav@1378
|
57 |
new InvHandler()
|
jaroslav@1378
|
58 |
);
|
jaroslav@1378
|
59 |
return 2 + anno.age();
|
jaroslav@412
|
60 |
}
|
jaroslav@412
|
61 |
|
jaroslav@1378
|
62 |
public static @interface Anno {
|
jaroslav@1378
|
63 |
public String name();
|
jaroslav@1378
|
64 |
public int age();
|
jaroslav@448
|
65 |
}
|
jaroslav@448
|
66 |
|
jaroslav@355
|
67 |
@Factory
|
jaroslav@355
|
68 |
public static Object[] create() {
|
jaroslav@1378
|
69 |
return VMTest.create(ProxyTest.class);
|
jaroslav@355
|
70 |
}
|
jaroslav@355
|
71 |
}
|