package com.atlassian.bitbucket.server;

import org.junit.Test;

import static com.atlassian.bitbucket.server.ApplicationMode.DEFAULT;
import static com.atlassian.bitbucket.server.ApplicationMode.MIRROR;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.junit.Assert.*;

public class ApplicationModeTest {

    @Test
    public void testFromId() {
        // straight ID -> AppMode
        assertEquals(of(DEFAULT), ApplicationMode.fromId(DEFAULT.getId()));
        assertEquals(of(MIRROR), ApplicationMode.fromId(MIRROR.getId()));
    }

    @Test
    public void testFromIdCaseInsensitive() {
        // verify that case does not matter
        assertEquals(of(DEFAULT), ApplicationMode.fromId(DEFAULT.getId().toLowerCase()));
        assertEquals(of(DEFAULT), ApplicationMode.fromId(DEFAULT.getId().toUpperCase()));
    }

    @Test
    public void testFromIdMismatch() {
        // mismatch should return default
        assertEquals(empty(), ApplicationMode.fromId("unsupported"));
    }

    @Test
    public void testFromIdNull() {
        assertEquals(empty(), ApplicationMode.fromId(null));
    }

}