package com.atlassian.bitbucket.mesh.app;

import com.atlassian.bitbucket.mesh.util.Version;
import org.junit.Test;

import static org.junit.Assert.*;

public class VersionUpdateTest {

    private static final Version ONE = new Version(1);
    private static final Version ONE_ONE = new Version(1, 1);
    private static final Version ONE_ONE_ONE = new Version(1, 1, 1);
    private static final Version TWO = new Version(2);

    @Test
    public void testOfForMajorDowngrade() {
        assertSame(VersionUpdate.MAJOR_DOWNGRADE, VersionUpdate.of(ONE, TWO));
    }

    @Test
    public void testOfForMajorUpgrade() {
        assertSame(VersionUpdate.MAJOR_UPGRADE, VersionUpdate.of(TWO, ONE));
    }

    @Test
    public void testOfForMinorDowngrade() {
        assertSame(VersionUpdate.MINOR_DOWNGRADE, VersionUpdate.of(ONE, ONE_ONE));
    }

    @Test
    public void testOfForMinorDowngradeInPatchVersion() {
        assertSame(VersionUpdate.MINOR_DOWNGRADE, VersionUpdate.of(ONE_ONE, ONE_ONE_ONE));
    }

    @Test
    public void testOfForMinorUpgrade() {
        assertSame(VersionUpdate.MINOR_UPGRADE, VersionUpdate.of(ONE_ONE, ONE));
    }

    @Test
    public void testOfForMinorUpgradeInPatchVersion() {
        assertSame(VersionUpdate.MINOR_UPGRADE, VersionUpdate.of(ONE_ONE_ONE, ONE_ONE));
    }

    @Test
    public void testOfForSameVersion() {
        assertSame(VersionUpdate.NONE, VersionUpdate.of(TWO, TWO));
    }

    @Test
    public void testIsUpgrade() {
        for (VersionUpdate update : VersionUpdate.values()) {
            assertEquals(update + " has an unexpected name/isUpgrade combination",
                    update.name().contains("UPGRADE"), update.isUpgrade());
        }
    }
}