class TestJavaClass(unittest.TestCase):

    def setUp(self):
        self.obj = JavaClass(data_dir+os.sep+'SimplePOJO.class')

    def test_declaration(self):
        self.assertEqual(self.obj.name, 'SimplePOJO')
        self.assertEqual(self.obj.package, '')
        self.assertEquals(self.obj.super_name, 'java.lang.Object')
        self.assertEquals(self.obj.interfaces, ['java.io.Serializable'])
        
        self.assertTrue(self.obj.public)
        self.assertTrue(self.obj.final)
        self.assertFalse(self.obj.abstract)
        self.assertFalse(self.obj.annotation)
        self.assertFalse(self.obj.enum)

    def test_fields(self):
        self.assertTrue(self.obj.fields)
        self.assertTrue(self._find_by_name(self.obj.fields, 'id'))
        self.assertTrue(self._find_by_name(self.obj.fields, 'name'))
        self.assertTrue(self._find_by_name(self.obj.fields, 'age'))
        self.assertTrue(self._find_by_name(self.obj.fields, 'cash'))
        self.assertTrue(self._find_by_name(self.obj.fields, 'matrix'))
        self.assertTrue(self._find_by_name(self.obj.fields, 'times'))

    def test_methods(self):
        self.assertTrue(self.obj.methods)
        self.assertTrue(self._find_by_name(self.obj.methods, 'doStuff'))
        self.assertTrue(self._find_by_name(self.obj.methods, 'toString'))

    def test_attributes(self):
        self.assertTrue(self.obj.attributes)
        self.assertTrue(self._find_by_name(self.obj.attributes, 'SourceFile'))

    def _find_by_name(self, seq, name):
        return filter(lambda it: it.name == name, seq) 

    def test_size(self):
        self.assertEquals(self.obj.size, 1455)
        self.assertEquals(self.obj.code_size, 426)

    def test_class_dependencies(self):
        self.assertEquals(self.obj.class_dependencies(), ['SimplePOJO', 
                                                          'java.io.Serializable', 
                                                          'java.lang.Double', 
                                                          'java.lang.Integer', 
                                                          'java.lang.Long', 
                                                          'java.lang.Object', 
                                                          'java.math.BigDecimal', 
                                                          'java.util.Date'])
    
    def test_package_dependencies(self):
        self.assertEquals(self.obj.package_dependencies(), ['', 
                                                            'java.io', 
                                                            'java.lang', 
                                                            'java.math', 
                                                            'java.util'])
Exemple #2
0
class TestJavaClass(unittest.TestCase):
    def setUp(self):
        self.obj = JavaClass(data_dir + os.sep + 'Java8Sample.class')

    def test_declaration(self):
        self.assertEqual(self.obj.name, 'Java8Sample')
        self.assertEqual(self.obj.package, '')
        self.assertEquals(self.obj.super_name, 'java.lang.Object')
        self.assertEquals(self.obj.interfaces, ['java.io.Serializable'])

        self.assertTrue(self.obj.public)
        self.assertTrue(self.obj.final)
        self.assertFalse(self.obj.abstract)
        self.assertFalse(self.obj.annotation)
        self.assertFalse(self.obj.enum)

    def test_fields(self):
        self.assertTrue(self.obj.fields)
        self.assertTrue(self._find_by_name(self.obj.fields, 'someTime'))

    def test_methods(self):
        self.assertTrue(self.obj.methods)
        self.assertTrue(self._find_by_name(self.obj.methods, 'simpleLambda'))
        self.assertTrue(self._find_by_name(self.obj.methods, 'simpleStream'))

    def test_attributes(self):
        self.assertTrue(self.obj.attributes)
        self.assertTrue(self._find_by_name(self.obj.attributes, 'SourceFile'))

    def _find_by_name(self, seq, name):
        return filter(lambda it: it.name == name, seq)

    def test_size(self):
        self.assertEquals(self.obj.size, 2463)
        self.assertEquals(self.obj.code_size, 320)

    def test_class_dependencies(self):
        self.assertEquals(self.obj.class_dependencies(), [
            'Java8Sample', 'java.io.PrintStream', 'java.io.Serializable',
            'java.lang.Object', 'java.lang.Runnable', 'java.lang.String',
            'java.lang.System', 'java.lang.invoke.LambdaMetafactory',
            'java.lang.invoke.MethodHandles',
            'java.lang.invoke.MethodHandles$Lookup', 'java.util.Arrays',
            'java.util.List', 'java.util.stream.Stream'
        ])

    def test_package_dependencies(self):
        self.assertEquals(self.obj.package_dependencies(), [
            '', 'java.io', 'java.lang', 'java.lang.invoke', 'java.util',
            'java.util.stream'
        ])
class TestJavaClass(unittest.TestCase):
    def setUp(self):
        self.obj = JavaClass(data_dir + os.sep + "Java8Sample.class")

    def test_declaration(self):
        self.assertEqual(self.obj.name, "Java8Sample")
        self.assertEqual(self.obj.package, "")
        self.assertEquals(self.obj.super_name, "java.lang.Object")
        self.assertEquals(self.obj.interfaces, ["java.io.Serializable"])

        self.assertTrue(self.obj.public)
        self.assertTrue(self.obj.final)
        self.assertFalse(self.obj.abstract)
        self.assertFalse(self.obj.annotation)
        self.assertFalse(self.obj.enum)

    def test_fields(self):
        self.assertTrue(self.obj.fields)
        self.assertTrue(self._find_by_name(self.obj.fields, "someTime"))

    def test_methods(self):
        self.assertTrue(self.obj.methods)
        self.assertTrue(self._find_by_name(self.obj.methods, "simpleLambda"))
        self.assertTrue(self._find_by_name(self.obj.methods, "simpleStream"))

    def test_attributes(self):
        self.assertTrue(self.obj.attributes)
        self.assertTrue(self._find_by_name(self.obj.attributes, "SourceFile"))

    def _find_by_name(self, seq, name):
        return filter(lambda it: it.name == name, seq)

    def test_size(self):
        self.assertEquals(self.obj.size, 2463)
        self.assertEquals(self.obj.code_size, 320)

    def test_class_dependencies(self):
        self.assertEquals(
            self.obj.class_dependencies(),
            [
                "Java8Sample",
                "java.io.PrintStream",
                "java.io.Serializable",
                "java.lang.Object",
                "java.lang.Runnable",
                "java.lang.String",
                "java.lang.System",
                "java.lang.invoke.LambdaMetafactory",
                "java.lang.invoke.MethodHandles",
                "java.lang.invoke.MethodHandles$Lookup",
                "java.util.Arrays",
                "java.util.List",
                "java.util.stream.Stream",
            ],
        )

    def test_package_dependencies(self):
        self.assertEquals(
            self.obj.package_dependencies(),
            ["", "java.io", "java.lang", "java.lang.invoke", "java.util", "java.util.stream"],
        )