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
|
package org.python.compiler.custom_proxymaker;
/*
* Tests support for various combinations of method signatures
*/
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.python.util.ProxyCompiler;
public class MethodSignatureTest {
Class<?> proxy;
@Before
public void setUp() throws Exception {
ProxyCompiler.compile("tests/python/custom_proxymaker/method_signatures.py",
"build/testclasses");
proxy = Class.forName("custom_proxymaker.tests.MethodSignatures");
}
@Test
public void methodThrows() throws Exception {
Method method = proxy.getMethod("throwsException");
assertArrayEquals(new Class<?>[] {RuntimeException.class}, method.getExceptionTypes());
}
@Test
public void returnsVoid() throws Exception {
Method method = proxy.getMethod("throwsException");
assertEquals(Void.TYPE, method.getReturnType());
}
@Test
public void returnsLong() throws Exception {
Method method = proxy.getMethod("returnsLong");
assertEquals(Long.TYPE, method.getReturnType());
}
@Test
public void returnsObject() throws Exception {
Method method = proxy.getMethod("returnsObject");
assertEquals(Object.class, method.getReturnType());
}
@Test
public void returnsArray() throws Exception {
Method method = proxy.getMethod("returnsArray");
Object compareType = Array.newInstance(Long.TYPE, 0);
assertEquals(compareType.getClass(), method.getReturnType());
}
@Test
public void returnsArrayObj() throws Exception {
Method method = proxy.getMethod("returnsArrayObj");
Object compareType = Array.newInstance(Object.class, 0);
assertEquals(compareType.getClass(), method.getReturnType());
}
@Test
@SuppressWarnings("unused")
public void acceptsString() throws Exception {
Class<?>[] partypes = new Class[] {String.class};
Method method = proxy.getMethod("acceptsString", partypes);
}
@Test
@SuppressWarnings("unused")
public void acceptsArray() throws Exception {
Object compareType = Array.newInstance(Long.TYPE, 0);
Class<?>[] partypes = new Class[] {compareType.getClass()};
Method method = proxy.getMethod("acceptsArray", partypes);
}
}
|