package com.atlassian.stash.internal.web.soy.functions;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

@RunWith(MockitoJUnitRunner.class)
public class CapIntFunctionTest {
    @Test
    public void testValidInputs() {
        assertThat(new CapIntFunction().apply("1", "99"), equalTo("1"));
        assertThat(new CapIntFunction().apply("100", "99"), equalTo("99+"));
        assertThat(new CapIntFunction().apply("99", "99"), equalTo("99"));
        assertThat(new CapIntFunction().apply("1", "10"), equalTo("1"));
        assertThat(new CapIntFunction().apply("11", "10"), equalTo("10+"));
        assertThat(new CapIntFunction().apply(1, 99), equalTo("1"));
        assertThat(new CapIntFunction().apply(100, 99), equalTo("99+"));
        assertThat(new CapIntFunction().apply("1", 99), equalTo("1"));
        assertThat(new CapIntFunction().apply("100", 99), equalTo("99+"));
        assertThat(new CapIntFunction().apply(1, "99"), equalTo("1"));
        assertThat(new CapIntFunction().apply(100, "99"), equalTo("99+"));
    }

    @Test(expected = NumberFormatException.class)
    public void testNullInput() {
        new CapIntFunction().apply(null, "99");
    }

    @Test(expected = NumberFormatException.class)
    public void testNullCap() {
        new CapIntFunction().apply(1, null);
    }

    @Test(expected = NumberFormatException.class)
    public void testNonNumberInput() {
        new CapIntFunction().apply("A", "99");
    }

    @Test(expected = NumberFormatException.class)
    public void testNonNumberCap() {
        new CapIntFunction().apply("1", "A");
    }
}
