def test_handle_program_finds_paths_and_calls_open_pager_with_alias(
    mock_page,
    mock_format,
    mock_get_paths,
    mock_get_contents,
    mock_resolve,
):
    """
    If there are entries for the program, handle_program needs to get the
    paths, get the contents, format the contents, and page the resulting
    string.
    """
    alias_for_program = 'link'
    resolved_program = 'ln'

    examples_dir = 'test-eg-dir'
    custom_dir = 'test-custom-dir'
    color_config = None
    use_color = False
    pager_cmd = 'foo bar'
    squeeze = False
    subs = ['foo', 'bar']

    file_contents = 'I am the contents of ln.md.'
    formatted_contents = 'and I am the formatted contents of ln.md.'

    test_config = _create_config(
        examples_dir=examples_dir,
        custom_dir=custom_dir,
        color_config=color_config,
        use_color=use_color,
        pager_cmd=pager_cmd,
        squeeze=squeeze,
        subs=subs
    )

    default_paths = ['test-eg-dir/ln.md']
    custom_paths = ['test-custom-dir/ln.md']

    def return_correct_path(*args, **kwargs):
        program_param = args[0]
        dir_param = args[1]
        if program_param != resolved_program:
            raise NameError(
                'expected ' +
                resolved_program +
                ', got ' +
                program_param
            )
        if dir_param == examples_dir:
            return default_paths
        elif dir_param == custom_dir:
            return custom_paths
        else:
            raise NameError(
                'got ' +
                dir_param +
                ', expected ' +
                examples_dir +
                ' or ' +
                custom_dir)

    mock_format.return_value = formatted_contents
    mock_get_paths.side_effect = return_correct_path
    mock_get_contents.return_value = file_contents
    mock_resolve.return_value = resolved_program

    util.handle_program(
        alias_for_program,
        test_config
    )

    mock_resolve.assert_called_once_with(
        alias_for_program,
        test_config
    )

    mock_get_paths.assert_any_call(
        resolved_program,
        examples_dir
    )
    mock_get_paths.assert_any_call(
        resolved_program,
        custom_dir,
    )

    mock_get_contents.assert_called_once_with(
        custom_paths[0],
        default_paths[0]
    )

    mock_format.assert_called_once_with(
        file_contents,
        use_color=test_config.use_color,
        color_config=test_config.color_config,
        squeeze=test_config.squeeze,
        subs=test_config.subs
    )

    mock_page.assert_called_once_with(
        formatted_contents,
        test_config.pager_cmd
    )

    If there are entries for the program, handle_program needs to get the
    paths, get the contents, format the contents, and page the resulting
    string.
    
test/util_test.py