package com.atlassian.bitbucket.util;

import com.atlassian.bitbucket.util.DateFormatter.FormatType;
import org.junit.Test;

import java.util.Locale;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class DateFormatterFormatTypeTest {

    @Test(expected = NullPointerException.class)
    public void testFromStringThrowsNullPointerException() {
        FormatType.fromString(null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testFromStringThrowIllegalArgumentExceptionWhenInvalidTypePassed() {
        FormatType.fromString("IamNotAType");
    }

    @Test
    public void testFromStringReturnsCorrectType() {
        for (FormatType type : FormatType.values()) {
            assertThat(type, equalTo(FormatType.fromString(type.name())));
        }
    }

    @Test
    public void testFromStringReturnsCorrectTypeForDifferentCase() {
        for (FormatType type : FormatType.values()) {
            assertThat(type, equalTo(FormatType.fromString(type.name().toLowerCase(Locale.ROOT))));
        }
    }
}