require 'test/unit' require 'mock_connection' require 'network/handler' class LogonHandler def state @state end end class HandlerTest < Test::Unit::TestCase def setup # create a connection and start it @conn = MockConnection.new @conn.switch_handler(LogonHandler.new(@conn)) assert_equal(:init,@conn.handler.state) @conn.update(:initdone) end def test_00_create_new assert_equal(:entername,@conn.handler.state) @conn.update("new") assert_equal(:enternewname,@conn.handler.state) @conn.update(" ") assert_equal(:enternewname,@conn.handler.state) @conn.update("test") assert_equal(:enternewpass,@conn.handler.state) @conn.update("pass") assert(@conn.handler.kind_of?(MenuHandler)) end def test_01_enter_existing assert_equal(:entername,@conn.handler.state) @conn.update("test") assert_equal(:enterpass,@conn.handler.state) @conn.update("pass") assert(@conn.handler.kind_of?(MenuHandler)) end def test_02_enter_non_existing assert_equal(:entername,@conn.handler.state) @conn.update("xxAragornxx") assert_equal(:entername,@conn.handler.state) end def test_03_enter_bad_pass assert_equal(:entername,@conn.handler.state) @conn.update("test") assert_equal(:enterpass,@conn.handler.state) @conn.update("bad") assert_equal(:enterpass,@conn.handler.state) end end