from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import unittest
from jnius.reflect import autoclass
from jnius import cast

class ReflectTest(unittest.TestCase):

    def test_stack(self):
        Stack = autoclass('java.util.Stack')
        stack = Stack()
        self.assertIsInstance(stack, Stack)
        stack.push('hello')
        stack.push('world')
        self.assertEqual(stack.pop(), 'world')
        self.assertEqual(stack.pop(), 'hello')
    
    def test_list_interface(self):
        ArrayList = autoclass('java.util.ArrayList')
        words = ArrayList()
        words.add('hello')
        words.add('world')
        self.assertIsNotNone(words.stream())
        self.assertIsNotNone(words.iterator())

    def test_super_interface(self):
        LinkedList = autoclass('java.util.LinkedList')
        words = LinkedList()
        words.add('hello')
        words.add('world')
        q = cast('java.util.Queue', words)
        self.assertEqual(2, q.size())
        self.assertIsNotNone(q.iterator())

    def test_super_object(self):
        LinkedList = autoclass('java.util.LinkedList')
        words = LinkedList()
        words.hashCode()

    def test_super_interface_object(self):
        LinkedList = autoclass('java.util.LinkedList')
        words = LinkedList()
        q = cast('java.util.Queue', words)
        q.hashCode()

    def test_list_iteration(self):
        ArrayList = autoclass('java.util.ArrayList')
        words = ArrayList()
        words.add('hello')
        words.add('world')
        self.assertEqual(['hello', 'world'], [word for word in words])


@@ -181,46 +181,1566 @@
 ast%0A
-%0Aclass ReflectTest(unittest.TestCase):
+from jnius.reflect import identify_hierarchy%0Afrom jnius import find_javaclass%0A%0Adef identify_hierarchy_dict(cls, level, concrete=True):%0A    return(%7B cls.getName() : level for cls,level in identify_hierarchy(cls, level, concrete) %7D)%0A%0A%0Aclass ReflectTest(unittest.TestCase):%0A%0A    def assertContains(self, d, clsName):%0A        self.assertTrue(clsName in d, clsName + %22 was not found in %22 + str(d))%0A%0A    def test_hierharchy_queue(self):%0A        d = identify_hierarchy_dict(find_javaclass(%22java.util.Queue%22), 0, False)%0A        self.assertContains(d, %22java.util.Queue%22)%0A        #super interfaces%0A        self.assertContains(d, %22java.util.Collection%22)%0A        self.assertContains(d, %22java.lang.Iterable%22)%0A        #all instantiated interfaces are rooted at Object%0A        self.assertContains(d, %22java.lang.Object%22)%0A        maxLevel = max(d.values())%0A        self.assertEqual(d%5B%22java.lang.Object%22%5D, maxLevel)%0A        self.assertEqual(d%5B%22java.util.Queue%22%5D, 0)%0A        %0A    def test_hierharchy_arraylist(self):%0A        d = identify_hierarchy_dict(find_javaclass(%22java.util.ArrayList%22), 0, True)%0A        self.assertContains(d, %22java.util.ArrayList%22)#concrete%0A        self.assertContains(d, %22java.util.AbstractCollection%22)#superclass%0A        self.assertContains(d, %22java.util.Collection%22)#interface%0A        self.assertContains(d, %22java.lang.Iterable%22)#interface%0A        self.assertContains(d, %22java.lang.Object%22)#root%0A        maxLevel = max(d.values())%0A        self.assertEqual(d%5B%22java.lang.Object%22%5D, maxLevel)%0A        self.assertEqual(d%5B%22java.util.ArrayList%22%5D, 0)%0A        
 %0A%0A  

test cases for identify_hierarchy