package com.njcn.gather.event.eventlist.service.impl;

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

public class EventWavePathResolverTest {

    public static void main(String[] args) {
        resolvesAbsoluteWavePath();
        resolvesRelativeWavePathWithMacPrefix();
        resolvesRelativeWavePathAlreadyContainingMac();
    }

    private static void resolvesAbsoluteWavePath() {
        EventWavePathResolver.WaveFilePath result = EventWavePathResolver.resolve("D:/", "AA-BB", "D:/wave/event-001.cfg");

        assertPathEquals(Paths.get("D:/wave/event-001.cfg"), result.getCfgPath(), "absolute cfg");
        assertPathEquals(Paths.get("D:/wave/event-001.dat"), result.getDatPath(), "absolute dat");
    }

    private static void resolvesRelativeWavePathWithMacPrefix() {
        EventWavePathResolver.WaveFilePath result = EventWavePathResolver.resolve("D:/wave-root", "AA-BB", "event-001");

        assertPathEquals(Paths.get("D:/wave-root/AA-BB/event-001.cfg"), result.getCfgPath(), "relative cfg");
        assertPathEquals(Paths.get("D:/wave-root/AA-BB/event-001.dat"), result.getDatPath(), "relative dat");
    }

    private static void resolvesRelativeWavePathAlreadyContainingMac() {
        EventWavePathResolver.WaveFilePath result = EventWavePathResolver.resolve("D:/wave-root", "AA-BB", "AA-BB/event-001.dat");

        assertPathEquals(Paths.get("D:/wave-root/AA-BB/event-001.cfg"), result.getCfgPath(), "relative mac cfg");
        assertPathEquals(Paths.get("D:/wave-root/AA-BB/event-001.dat"), result.getDatPath(), "relative mac dat");
    }

    private static void assertPathEquals(Path expected, Path actual, String label) {
        if (!expected.normalize().equals(actual.normalize())) {
            throw new AssertionError(label + " expected " + expected + " but got " + actual);
        }
    }
}
