Beispiel #1
0
 def test_constructor(self):
     """Constructs a Java object from a constructor.
     """
     Vector = pyjava.getclass('java.util.Vector')
     vector = Vector(10)
     self.assertIsNotNone(vector)
     self.assertEqual(vector.capacity(), 10)
Beispiel #2
0
 def test_badoverload(self):
     """Calls an existing method but with wrong argument types.
     """
     Math = pyjava.getclass('java.lang.Math')
     self.assertRaises(
             pyjava.NoMatchingOverload,
             Math.sin,
             4, 2)
     self.assertRaises(
             pyjava.NoMatchingOverload,
             Math.sin)
Beispiel #3
0
    def test_nonexistent(self):
        """Accesses an unknown method.

        This should be detected when accessing.
        """
        String = pyjava.getclass('java.lang.String')

        def test_func():
            m = String.nonexistentMethod
        self.assertRaises(
                AttributeError,
                test_func)
Beispiel #4
0
 def setUp(self):
     self.character = pyjava.getclass('java.lang.Character')
     self.v = self.character(u'v')
Beispiel #5
0
 def setUp(self):
     self.bool_ = pyjava.getclass('java.lang.Boolean')
     self.True_ = self.bool_(True)
     self.False_ = self.bool_(False)
Beispiel #6
0
 def test_staticmethod(self):
     """Calls a well-known static method.
     """
     Math = pyjava.getclass('java.lang.Math')
     self.assertAlmostEqual(Math.sin(math.pi / 2), 1.0)
Beispiel #7
0
 def test_method(self):
     """Calls a well-known method on a wrapper returned by a static method.
     """
     Collections = pyjava.getclass('java.util.Collections')
     li = Collections.emptyList()
     self.assertEqual(li.size(), 0)
Beispiel #8
0
 def test_staticmethod(self):
     """Accesses a well-known static method.
     """
     Math = pyjava.getclass('java.lang.Math')
     self.assertTrue(isinstance(Math.sin, pyjava._UnboundJavaMethod))
Beispiel #9
0
 def test_method(self):
     """Accesses a well-known method.
     """
     String = pyjava.getclass('java.lang.String')
     self.assertTrue(isinstance(String.length, pyjava._UnboundJavaMethod))
Beispiel #10
0
 def test_String(self):
     """Wraps a well-known class.
     """
     String = pyjava.getclass('java.lang.String')
     self.assertIsNotNone(String)