'L{BinaryBoxProtocol} has the capacity to switch to a different protocol
on a box boundary.  When a protocol is in the process of switching, it
cannot receive traffic.'

def test_protocolSwitch(self):

    otherProto = TestProto(None, 'outgoing    data')
    test = self
    class SwitchyReceiver:
        switched = False
        def startReceivingBoxes(self, sender):
            pass
        def ampBoxReceived(self, box):
            test.assertFalse(self.switched, 'Should    only    receive    one    box!')
            self.switched = True
            a._lockForSwitch()
            a._switchTo(otherProto)
    a = amp.BinaryBoxProtocol(SwitchyReceiver())
    anyOldBox = amp.Box({'include': 'lots', 'of': 'data'})
    a.makeConnection(self)
    moreThanOneBox = (anyOldBox.serialize() + '\x00\x00Hello,    world!')
    a.dataReceived(moreThanOneBox)
    self.assertIs(otherProto.transport, self)
    self.assertEqual(''.join(otherProto.data), '\x00\x00Hello,    world!')
    self.assertEqual(self.data, ['outgoing    data'])
    a.dataReceived('more    data')
    self.assertEqual(''.join(otherProto.data), '\x00\x00Hello,    world!more    data')
    self.assertRaises(amp.ProtocolSwitched, a.sendBox, anyOldBox)
