Debian Codegraph @

test/jpypetest/test_reflect.py

raw symbols SCIP
1 # *****************************************************************************
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 # See NOTICE file for details.
16 #
17 # *****************************************************************************
18 import sys
19 import jpype
20 from jpype import JPackage, JArray, JByte, java
21 import common
22
23
24 class ReflectCase(common.JPypeTestCase):
25
26 def setUp(self):
27 common.JPypeTestCase.setUp(self)
28 self.test1 = jpype.JClass('jpype.overloads.Test1')()
29 self.Reflect = jpype.JClass('jpype.reflect.ReflectionTest')
30 self.Annotation = jpype.JClass('jpype.reflect.Annotation')
31
32 def testClass(self):
33 t = jpype.JClass('java.lang.Object')
34 obj = self.Reflect()
35 self.assertEqual('Class', self.test1.testClassVsObject(self.Reflect))
36 self.assertEqual(
37 'Class', self.test1.testClassVsObject(self.Reflect.class_))
38 self.assertEqual(
39 'Class', self.test1.testClassVsObject(obj.getClass()))
40 self.assertEqual(
41 'Class', self.test1.testClassVsObject(obj.__class__.class_))
42
43 def testAnnotation(self):
44 method = self.Reflect.class_.getMethod('annotatedMethod')
45 annotation = method.getAnnotation(self.Annotation)
46 self.assertEqual('annotation', annotation.value())
47
48 def testCallPublicMethod(self):
49 method = self.Reflect.class_.getMethod('publicMethod')
50 obj = self.Reflect()
51 self.assertIsNotNone(obj)
52 self.assertIsNotNone(method)
53 self.assertEqual('public', method.invoke(obj))
54
55 def testCallPrivateMethod(self):
56 method = self.Reflect.class_.getDeclaredMethod('privateMethod')
57 method.setAccessible(True)
58 obj = self.Reflect()
59 self.assertIsNotNone(obj)
60 self.assertIsNotNone(method)
61 self.assertEqual('private', method.invoke(obj))
62
63 def testAccessPublicField(self):
64 field = self.Reflect.class_.getField('publicField')
65 obj = self.Reflect()
66 self.assertIsNotNone(obj)
67 self.assertIsNotNone(field)
68 self.assertEqual('public', field.get(obj))
69
70 def testAccessPrivateField(self):
71 field = self.Reflect.class_.getDeclaredField('privateField')
72 obj = self.Reflect()
73 field.setAccessible(True)
74 self.assertIsNotNone(obj)
75 self.assertIsNotNone(field)
76 self.assertEqual('private', field.get(obj))