package be.ehealth.technicalconnector.adapter;

import lombok.AllArgsConstructor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;

@RunWith(Parameterized.class)
@AllArgsConstructor
public class XmlDurationAdapterTest {

    private String inputDuration;
    private long expectedMillis;
    private String outputDuration;

    @Parameterized.Parameters(name = "{index}: duration({0}")
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][]{
                {"PT5S", 5000L, "PT5S"},
                {"PT65S", 65000L, "PT1M5S"}
        });
    }

    @Test
    public void execute() throws Exception {
        XmlDurationAdapter adapter = new XmlDurationAdapter();
        Duration duration = adapter.unmarshal(inputDuration);
        Assert.assertEquals(expectedMillis, duration.toMillis());
        Assert.assertEquals(outputDuration, adapter.marshal(duration));
    }
}