def setUp(self):
     super(TestNetworkManagerState, self).setUp()
     self.network_manager = self.mocker.mock()
     self.is_connected = self.mocker.replace(
         'ubuntuone.networkstate.windows.is_machine_connected')
     self.thread = self.mocker.mock()
     self.cb = self.mocker.mock()
     self.state = NetworkManagerState(self.cb)
class TestNetworkManagerState(MockerTestCase):
    """Test the Network Manager State."""

    def setUp(self):
        super(TestNetworkManagerState, self).setUp()
        self.network_manager = self.mocker.mock()
        self.is_connected = self.mocker.replace(
            'ubuntuone.networkstate.windows.is_machine_connected')
        self.thread = self.mocker.mock()
        self.cb = self.mocker.mock()
        self.state = NetworkManagerState(self.cb)

    def test_connection_made(self):
        """Test that the cb is actually called."""
        self.cb(ONLINE)
        self.mocker.replay()
        self.state.connection_made()

    def test_connection_lost(self):
        """Test that the cb is actually called."""
        self.cb(OFFLINE)
        self.mocker.replay()
        self.state.connection_lost()

    def test_find_online_state_not_connected(self):
        """Test that we do find the online state correctly."""
        self.is_connected()
        self.mocker.result(False)
        self.cb(OFFLINE)
        self.mocker.result(self.thread)
        self.thread.daemon = True
        self.thread.start()
        self.mocker.replay()
        self.state.find_online_state(listener=self.network_manager,
                                     listener_thread=self.thread)

    def test_find_online_state_connected(self):
        """Test that we do find the online state correctly."""
        self.is_connected()
        self.mocker.result(ONLINE)
        self.cb(ONLINE)
        self.mocker.result(self.thread)
        self.thread.daemon = True
        self.thread.start()
        self.mocker.replay()
        self.state.find_online_state(listener=self.network_manager,
                                     listener_thread=self.thread)