File: MethodSignatureTest.java

package info (click to toggle)
jython 2.7.1%2Brepack1-4~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 63,416 kB
  • sloc: python: 639,274; java: 296,480; xml: 1,743; sh: 396; ansic: 126; makefile: 72
file content (77 lines) | stat: -rw-r--r-- 2,391 bytes parent folder | download | duplicates (2)
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
package org.python.compiler.custom_proxymaker;

/*
 * Tests support for various combinations of method signatures
 */

import static org.junit.Assert.*;

import java.lang.reflect.*;

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/classes");
        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);
    }

}