def test_find_command(self, command_mock, which_mock):
        """
        Test the `find_command` class method
        """

        which_mapping = {}
        which_mock.side_effect = \
            lambda cmd, path=None: which_mapping.get(cmd, None)

        # Neither pg_receivewal, neither pg_receivexlog are
        # available, and the result is a CommandFailedException
        with pytest.raises(CommandFailedException):
            PgReceiveXlog.find_command()

        # pg_receivexlog is available, but pg_receivewal is not
        which_mapping['pg_receivexlog'] = '/usr/bin/pg_receivexlog'
        command = PgReceiveXlog.find_command()
        assert command_mock.mock_calls == [
            mock.call('/usr/bin/pg_receivexlog', check=True, path=None),
            mock.call()('--version'),
        ]
        assert command == command_mock.return_value

        # pg_receivewal is also available, but it's only a shim
        which_mapping['pg_receivewal'] = '/usr/bin/pg_receivewal'
        command_mock.reset_mock()
        command_mock.return_value.side_effect = [CommandFailedException, None]
        command = PgReceiveXlog.find_command()
        assert command_mock.mock_calls == [
            mock.call('/usr/bin/pg_receivewal', check=True, path=None),
            mock.call()('--version'),
            mock.call('/usr/bin/pg_receivexlog', check=True, path=None),
            mock.call()('--version'),
        ]
        assert command == command_mock.return_value

        # pg_receivewal is available and works well
        command_mock.reset_mock()
        command_mock.return_value.side_effect = None
        command = PgReceiveXlog.find_command()
        assert command_mock.mock_calls == [
            mock.call('/usr/bin/pg_receivewal', check=True, path=None),
            mock.call()('--version'),
        ]
        assert command == command_mock.return_value