func TestProcessorFactory(t *testing.T) {
	Convey("ProcessorFactory", t, func() {
		physics := processor.DefaultPhysics()
		physics.TurnCommandModifier = 1.0
		physics.AccelerationCommandModifier = 1.0
		factory := processor.NewFactory(&physics)

		t := cmd.NewTurn(1)
		t_comm := cmd.GameCommand(&t)
		turn_cp := factory.GetCommandProcessor(&t_comm)
		So(turn_cp, ShouldHaveSameTypeAs, &processor.TurnCommandProcessor{Physics: &physics})

		a := cmd.NewAcceleration(1)
		a_comm := cmd.GameCommand(&a)
		acceleration_cp := factory.GetCommandProcessor(&a_comm)
		So(acceleration_cp, ShouldHaveSameTypeAs, &processor.AccelerationCommandProcessor{Physics: &physics})

		c := cmd.NewConnect("test")
		c_comm := cmd.GameCommand(&c)
		connect_cp := factory.GetCommandProcessor(&c_comm)
		So(connect_cp, ShouldHaveSameTypeAs, &processor.ConnectCommandProcessor{Physics: &physics})

		f := cmd.NewFire()
		f_comm := cmd.GameCommand(&f)
		fire_cp := factory.GetCommandProcessor(&f_comm)
		So(fire_cp, ShouldHaveSameTypeAs, &processor.FireCommandProcessor{Physics: &physics})

		b := cmd.BaseCommand{}
		b_comm := cmd.GameCommand(&b)
		base_cp := factory.GetCommandProcessor(&b_comm)
		So(base_cp, ShouldEqual, nil)
	})
}
func TestFire(t *testing.T) {
	Convey("Fire Command", t, func() {
		fire := cmd.NewFire()
		So(fire.UniqueId, ShouldEqual, "")
		So(fire.Subtype, ShouldEqual, cmd.Fire)
		So(fire.Type, ShouldEqual, cmd.Post)
		So(fire.Type, ShouldEqual, fire.Command().Type)
		So(fire.Subtype, ShouldEqual, fire.Command().Subtype)
		So(fire.UniqueId, ShouldEqual, fire.Command().UniqueId)
	})
}
func TestFireProcessor(t *testing.T) {
	Convey("Fire Processor", t, func() {
		physics := processor.DefaultPhysics()
		physics.TurnCommandModifier = 1.0
		physics.AccelerationCommandModifier = 1.0
		fireProcessor := processor.FireCommandProcessor{Physics: &physics}
		connectProcessor := processor.ConnectCommandProcessor{Physics: &physics}

		fireCommand := cmd.NewFire()
		fireCommand.UserId = "abc"

		connectCommand := cmd.NewConnect("abc")
		connectCommand.UserId = "abc"

		fire := cmd.GameCommand(&fireCommand)
		connect := cmd.GameCommand(&connectCommand)

		game_state := physics.NewGameState()
		So(len(game_state.Bullets), ShouldEqual, 0)
		So(len(game_state.Vehicles), ShouldEqual, 0)

		connectProcessor.Run(&game_state, connect)
		So(len(game_state.Vehicles), ShouldEqual, 1)

		fireProcessor.Run(&game_state, fire)
		So(len(game_state.Bullets), ShouldEqual, 1)

		badFireCommand := cmd.NewFire()
		badFireCommand.UserId = "nobody"
		badFire := cmd.GameCommand(&badFireCommand)

		fireProcessor.Run(&game_state, badFire)
		So(len(game_state.Bullets), ShouldEqual, 1)

	})
}
func TestDecodeFire(t *testing.T) {
	Convey("Fire Decode", t, func() {
		formatter := encoder.JsonEncoderDecoder{Tag: "DecodeTest"}

		data := cmd.NewFire()
		data.UniqueId = "ABC123"
		buffer, error := json.Marshal(data)

		command, err := formatter.Decode(buffer)

		turn := command.(*cmd.FireCommand)

		So(error, ShouldEqual, nil)
		So(turn.Command().Type, ShouldEqual, cmd.Post)
		So(turn.Command().Subtype, ShouldEqual, cmd.Fire)
		So(err, ShouldEqual, nil)
		So(turn.Command().UniqueId, ShouldEqual, "ABC123")
	})
}