org.brocalc.calculator.BrokerageCalculatorSIT.java Source code

Java tutorial

Introduction

Here is the source code for org.brocalc.calculator.BrokerageCalculatorSIT.java

Source

/*******************************************************************************
 * Copyright (c) 2013 51zero Ltd.
 *
 * This file is part of the Brokerage Calculation Library (brocalc).
 *
 * brocalc is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * brocalc is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even he implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with brocalc.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package org.brocalc.calculator;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.math.BigDecimal;

import javax.annotation.Resource;

import org.brocalc.calculator.BrokerageSchedule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.brocalc.domain.Broker;
import org.brocalc.domain.BrokerageAmount;
import org.brocalc.domain.Currency;
import org.brocalc.domain.TradeInfo;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/spring/scenario.xml")
public class BrokerageCalculatorSIT {

    @Resource
    private BrokerageSchedule brokerageSchedule;

    @Test
    public void testBrokerSchedule() {
        Broker broker = new Broker("Test-Broker");
        TradeInfo tradeInfo = mock(TradeInfo.class);
        when(tradeInfo.getBroker()).thenReturn(broker);
        when(tradeInfo.getCurrency()).thenReturn(Currency.getInstance("ZAR"));
        when(tradeInfo.getUsdAmount()).thenReturn(new BigDecimal(13000000));
        BrokerageAmount brokerageAmount = brokerageSchedule.calculateBrokerage(tradeInfo);

        assertEquals("USD", brokerageAmount.getCurrency().getCurrencyCode());
        assertEquals(BigDecimal.ONE.setScale(2), brokerageAmount.getAmount());
    }

}