package com.atlassian.bitbucket.mesh.repository;

import org.junit.Test;

import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

public class DefaultPathRepositoryTest {

    @Test
    public void testBasicProperties() {
        Path path = Paths.get("space in path/\uF603 SMiley").toAbsolutePath();

        PathRepository repository = new DefaultPathRepository(path);

        assertEquals("path:" + path, repository.getId());
        assertEquals(path, repository.getPath());
        assertEquals("-smiley", repository.getSlug());
    }

    @Test
    public void testEquals() {
        Path path = Paths.get("repositories/1234").toAbsolutePath();
        PathRepository repository = new DefaultPathRepository(path);

        //Verify equals works as expected
        assertEquals(repository, new DefaultPathRepository(path));
        assertNotEquals(repository, new DefaultPathRepository(path.resolve("sub")));
    }

    @Test
    public void testRelativePath() {
        PathRepository repo1 = new DefaultPathRepository(Paths.get("repositories/1234").toAbsolutePath());
        PathRepository repo2 = new DefaultPathRepository(Paths.get("repositories/5678").toAbsolutePath());

        assertEquals(Paths.get("../1234"), repo1.getRelativePath(repo2));
        assertEquals(Paths.get(""), repo1.getRelativePath(repo1));
    }
}