package org.javafunk.funk;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.RoundingMode;

import static org.hamcrest.Matchers.is;
import static org.javafunk.funk.BigDecimals.*;
import static org.junit.Assert.*;

public class BigDecimalsTest {
    @Test
    public void returnsMapperFromLongToBigDecimal() {
        assertThat(fromLongToBigDecimal().map(123L), is(new BigDecimal("123")));
    }

    @Test
    public void returnsMapperFromDoubleToBigDecimal() {
        assertThat(fromDoubleToBigDecimal().map(123.45D).setScale(2, RoundingMode.DOWN), is(new BigDecimal("123.45")));
    }

    @Test
    public void returnsMapperFromIntegerToBigDecimal() {
        assertThat(fromIntegerToBigDecimal().map(123), is(new BigDecimal("123")));
    }

    @Test
    public void returnsMapperFromStringToBigDecimal() {
        assertThat(fromStringToBigDecimal().map("123.45"), is(new BigDecimal("123.45")));
    }

    @Test
    public void returnsMapperFromBigDecimalToPlainString() {
        assertThat(toPlainString().map(new BigDecimal("123.456")), is("123.456"));
    }

    @Test
    public void returnsMapperWhichScalesBigDecimalAccordingToSuppliedArguments() {
        assertThat(BigDecimals.toScaled(2, RoundingMode.HALF_UP).map(new BigDecimal("123.455")),
                is(new BigDecimal("123.46")));
        assertThat(BigDecimals.toScaled(1, RoundingMode.HALF_DOWN).map(new BigDecimal("123.45")),
                is(new BigDecimal("123.4")));
    }

    @Test
    public void providesLiteralsForBigDecimals() {
        assertThat(bigDecimal(123), is(new BigDecimal("123")));
        assertThat(bigDecimal(123L), is(new BigDecimal("123")));
        assertThat(bigDecimal(123.45D).setScale(2, RoundingMode.DOWN), is(new BigDecimal("123.45")));
        assertThat(bigDecimal("123.45"), is(new BigDecimal("123.45")));
    }
}
@@ -1,8 +1,263 @@
+/*%0A * Copyright (C) 2011-Present Funk committers.%0A * All rights reserved.%0A *%0A * The software in this package is published under the terms of the BSD%0A * style license a copy of which has been included with this distribution in%0A * the LICENSE.txt file.%0A */%0A
 package 

Add copyright preamble to BigDecimalsTest.