def testAddBeanWithoutResolver(self): container = BeanContainer(Person) try: container.addBean(Person('John')) self.fail() except self.IllegalStateException: pass # should get exception try: container.addBeanAfter(None, Person('Jane')) self.fail() except self.IllegalStateException: pass # should get exception try: container.addBeanAt(0, Person('Jack')) self.fail() except self.IllegalStateException: pass # should get exception try: container.addAll( [Person('Jack')] ) self.fail() except self.IllegalStateException: pass # should get exception self.assertEquals(0, len(container))
def testAddBeanWithPropertyResolver(self): container = BeanContainer(Person) container.setBeanIdProperty('name') self.assertNotEquals(container.addBean(Person('John')), None) self.assertNotEquals(container.addBeanAfter(None, Person('Jane')), None) self.assertNotEquals(container.addBeanAt(0, Person('Jack')), None) container.addAll( [Person('Jill'), Person('Joe')] ) self.assertTrue(container.containsId('John')) self.assertTrue(container.containsId('Jane')) self.assertTrue(container.containsId('Jack')) self.assertTrue(container.containsId('Jill')) self.assertTrue(container.containsId('Joe')) self.assertEquals(3, container.indexOfId('Jill')) self.assertEquals(4, container.indexOfId('Joe')) self.assertEquals(5, len(container))