package org.innovateuk.ifs.finance.resource.cost;

import org.junit.Before;
import org.junit.Test;

import java.math.BigDecimal;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class LabourCostTest {

    LabourCost labourCost;
    private Long id;
    private String key;
    private String role;
    private BigDecimal grossEmployeeCost;
    private Integer labourDays;
    private String description;

    @Before
    public void setUp() throws Exception {
        id = 0L;
        key = "Labour";
        role = "Manager";
        grossEmployeeCost = new BigDecimal(50000);
        labourDays = new Integer(168);
        description = "";

        labourCost = new LabourCost(id, key, role, grossEmployeeCost, labourDays,  description, 1L);
    }

    @Test
    public void labourCostShouldReturnCorrectBaseAttributesTest() throws Exception {
        assert(labourCost.getId().equals(id));
        assert(labourCost.getRole().equals(role));
        assert(labourCost.getGrossEmployeeCost().equals(grossEmployeeCost));
        assert(labourCost.getLabourDays().equals(labourDays));
        assert(labourCost.getDescription().equals(description));
    }

    @Test
    public void getRateTest() throws Exception {
        Integer workingDaysPerYear = new Integer(232);
        BigDecimal ratePerDay = labourCost.getRate(workingDaysPerYear);
        BigDecimal expected = new BigDecimal(215.51724).setScale(5, BigDecimal.ROUND_HALF_EVEN);
        assertEquals(expected, ratePerDay);
    }

    @Test
    public void rateNullLabourDaysTest() throws Exception {
        Integer workingDaysPerYear = null;
        BigDecimal ratePerDay = labourCost.getRate(workingDaysPerYear);
        assertNull(ratePerDay);
    }

    @Test
    public void rateWithDivisionByZeroLabourDaysTest() throws Exception {
        int workingDaysPerYear = 0;
        BigDecimal ratePerDay = labourCost.getRate(workingDaysPerYear);
        assertEquals(BigDecimal.ZERO, ratePerDay);
    }

    @Test
    public void getRateWithoutGrossEmployeeCost() throws Exception {
        int workingDaysPerYear = 50;
        labourCost.setGrossEmployeeCost(BigDecimal.ZERO);
        BigDecimal ratePerDay = labourCost.getRate(workingDaysPerYear);
        assertEquals(labourCost.getRate(), ratePerDay);
    }

    @Test
    public void getLabourCostTotalTest() throws Exception {
        Integer workingDaysPerYear = new Integer(232);
        BigDecimal totalLabourCost = labourCost.getTotal(workingDaysPerYear);
        BigDecimal expected = new BigDecimal(36206.89632).setScale(5, BigDecimal.ROUND_HALF_EVEN);
        BigDecimal totalStoredLabourCost = labourCost.getTotal();
        assertEquals(expected, totalLabourCost);
        assertEquals(expected, totalStoredLabourCost);
    }

    @Test
    public void getLabourCostTotalWithoutLabourDaysTest() throws Exception {
        Integer workingDaysPerYear = new Integer(232);
        labourCost.setLabourDays(null);
        BigDecimal totalLabourCost = labourCost.getTotal(workingDaysPerYear);
        assertEquals(BigDecimal.ZERO, totalLabourCost);
    }

    @Test
    public void setRoleTest() throws Exception {
        labourCost.setRole("Developer");
        assertEquals("Developer", labourCost.getRole());
    }
}

@@ -247,16 +247,24 @@
  %7B%0A%0A    
+private 
 LabourCo
@@ -653,24 +653,11 @@
 s = 
-new Integer(
 168
-)
 ;%0A  
@@ -762,17 +762,16 @@
 ourDays,
- 
  descrip
@@ -863,33 +863,16 @@
 esTest()
- throws Exception
  %7B%0A     
@@ -872,32 +872,33 @@
 %7B%0A        assert
+ 
 (labourCost.getI
@@ -920,32 +920,33 @@
 ;%0A        assert
+ 
 (labourCost.getR
@@ -972,32 +972,33 @@
 ;%0A        assert
+ 
 (labourCost.getG
@@ -1050,32 +1050,33 @@
 ;%0A        assert
+ 
 (labourCost.getL
@@ -1122,16 +1122,17 @@
   assert
+ 
 (labourC
@@ -1220,33 +1220,16 @@
 teTest()
- throws Exception
  %7B%0A     
@@ -1260,32 +1260,19 @@
 rYear = 
-new Integer(
 232
-)
 ;%0A      
@@ -1535,33 +1535,16 @@
 ysTest()
- throws Exception
  %7B%0A     
@@ -1756,33 +1756,16 @@
 ysTest()
- throws Exception
  %7B%0A     
@@ -1984,33 +1984,16 @@
 eeCost()
- throws Exception
  %7B%0A     
@@ -2267,33 +2267,16 @@
 alTest()
- throws Exception
  %7B%0A     
@@ -2307,32 +2307,19 @@
 rYear = 
-new Integer(
 232
-)
 ;%0A      
@@ -2733,33 +2733,16 @@
 ysTest()
- throws Exception
  %7B%0A     
@@ -2777,24 +2777,11 @@
 r = 
-new Integer(
 232
-)
 ;%0A  
@@ -2998,33 +2998,16 @@
 leTest()
- throws Exception
  %7B%0A     
@@ -3106,9 +3106,8 @@
 %0A    %7D%0A%7D
-%0A

Format and code clean up for LabourCostTest