'When the factory\'s C{buildProtocol} returns L{None} the connection is
gracefully closed.'

def test_buildProtocolReturnsNone(self):

    connectionLost = Deferred()
    reactor = self.buildReactor()
    serverFactory = MyServerFactory()
    serverFactory.protocolConnectionLost = connectionLost
    stopOnError(self, reactor)
    class NoneFactory(ServerFactory, ):
        def buildProtocol(self, address):
            return None
    listening = self.endpoints.server(reactor).listen(serverFactory)
    def listened(port):
        clientFactory = NoneFactory()
        endpoint = self.endpoints.client(reactor, port.getHost())
        return endpoint.connect(clientFactory)
    connecting = listening.addCallback(listened)
    def connectSucceeded(protocol):
        self.fail(('Stream    client    endpoint    connect    succeeded    with    %r,    should    have    failed    with    NoProtocol.' % (protocol,)))
    def connectFailed(reason):
        reason.trap(NoProtocol)
    connecting.addCallbacks(connectSucceeded, connectFailed)
    def connected(ignored):
        return connectionLost
    disconnecting = connecting.addCallback(connected)
    disconnecting.addErrback(log.err)
    def disconnected(ignored):
        reactor.stop()
    disconnecting.addCallback(disconnected)
    self.runReactor(reactor)
