def test_ask_and_validate(self):
        """
        DialogHelper.ask_and_validate() behaves properly
        """
        dialog = DialogHelper()
        helper_set = HelperSet([FormatterHelper()])
        dialog.set_helper_set(helper_set)

        question = 'What color was the white horse of Henry IV?'
        error = 'This is not a color!'

        def validator(color):
            if color not in ['white', 'black']:
                raise Exception(error)

            return color

        dialog.set_input_stream(self.get_input_stream('\nblack\n'))
        self.assertEqual('white', dialog.ask_and_validate(self.get_output_stream(), question, validator, 2, 'white'))
        self.assertEqual('black', dialog.ask_and_validate(self.get_output_stream(), question, validator, 2, 'white'))

        dialog.set_input_stream(self.get_input_stream('green\nyellow\norange\n'))
        self.assertRaises(Exception,
                          dialog.ask_and_validate,
                          self.get_output_stream(), question, validator, 2, 'white')