BigDecimal result = new BigDecimal(0); Map results = new HashMap(); <<<<<<< HEAD EntityTree operationComponents = technology.getTreeField("operationComponents"); for (Entity operationComponent : operationComponents) { EntityList inputProducts = operationComponent.getHasManyField("operationProductInComponents"); for (Entity inputProduct : inputProducts) { BigDecimal quantityInputProduct = (BigDecimal) inputProduct.getField("quantity"); Entity product = inputProduct.getBelongsToField("product"); BigDecimal includeCostOfMaterial = (BigDecimal) product.getField(mode.getStrValue()); BigDecimal costForNumber = (BigDecimal) product.getField("costForNumber"); BigDecimal costPerPrice = includeCostOfMaterial.divide(costForNumber); BigDecimal costQuantityFromPorduct = costPerPrice.multiply(quantityInputProduct); result = result.add(costQuantityFromPorduct); } } result = result.multiply(quantity); results.put("materialCost", result); ======= // if (technology != null) { EntityTree operationComponents = technology.getTreeField("operationComponents"); checkArgument(operationComponents != null, "operationComponents is null"); checkArgument(operationComponents.size() > 0, "operationComponents is empty"); // if (!operationComponents.isEmpty()) { for (Entity operationComponent : operationComponents) { EntityList inputProducts = operationComponent.getHasManyField("operationProductInComponents"); for (Entity inputProduct : inputProducts) { BigDecimal quantityInputProduct = (BigDecimal) inputProduct.getField("quantity"); Entity product = inputProduct.getBelongsToField("product"); BigDecimal includeCostOfMaterial = (BigDecimal) product.getField(mode.getStrValue()); BigDecimal costForNumber = (BigDecimal) product.getField("costForNumber"); BigDecimal costPerPrice = includeCostOfMaterial.divide(costForNumber); BigDecimal costQuantityFromPorduct = costPerPrice.multiply(quantityInputProduct); result = result.add(costQuantityFromPorduct); } } result = result.multiply(quantity); results.put("materialCost", result); // } // } >>>>>>> 011ab96d2cfc58d32f8fb38407d197b339ffd921 return results; } }
BigDecimal result = new BigDecimal(0); Map results = new HashMap(); EntityTree operationComponents = technology.getTreeField("operationComponents"); for (Entity operationComponent : operationComponents) { EntityList inputProducts = operationComponent.getHasManyField("operationProductInComponents"); for (Entity inputProduct : inputProducts) { BigDecimal quantityInputProduct = (BigDecimal) inputProduct.getField("quantity"); Entity product = inputProduct.getBelongsToField("product"); BigDecimal includeCostOfMaterial = (BigDecimal) product.getField(mode.getStrValue()); BigDecimal costForNumber = (BigDecimal) product.getField("costForNumber"); BigDecimal costPerPrice = includeCostOfMaterial.divide(costForNumber); BigDecimal costQuantityFromPorduct = costPerPrice.multiply(quantityInputProduct); result = result.add(costQuantityFromPorduct); } } result = result.multiply(quantity); results.put("materialCost", result); return results; } }
import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; <<<<<<< HEAD ======= import static org.mockito.AdditionalMatchers.lt; >>>>>>> 011ab96d2cfc58d32f8fb38407d197b339ffd921 import java.math.BigDecimal; import java.util.Arrays;
import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.math.BigDecimal; import java.util.Arrays;
import java.math.BigDecimal; import java.util.Arrays; import java.util.Collection; <<<<<<< HEAD import java.util.Iterator; ======= >>>>>>> 011ab96d2cfc58d32f8fb38407d197b339ffd921 import java.util.Map; import org.junit.Before;
import java.math.BigDecimal; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.Map; import org.junit.Before;
import com.qcadoo.model.api.EntityList; import com.qcadoo.model.api.EntityTree; <<<<<<< HEAD @RunWith(Parameterized.class) public class ParameterizedProductsCostCalculationServiceTest { ======= //@RunWith(Parameterized.class) public class ParameterizedProductsCostCalculationServiceTest { /* >>>>>>> 011ab96d2cfc58d32f8fb38407d197b339ffd921 private ProductsCostCalculationService productCostCalc; private Entity technology;
import com.qcadoo.model.api.EntityList; import com.qcadoo.model.api.EntityTree; @RunWith(Parameterized.class) public class ParameterizedProductsCostCalculationServiceTest { private ProductsCostCalculationService productCostCalc; private Entity technology;
private BigDecimal validationAverage, validationLastPurchase, validationNominal, validationInputQuantity, validationOrderQuantity, validationExpectedResult; <<<<<<< HEAD private BigDecimal validationCostForNumber; ======= private Integer validationCostForNumber; >>>>>>> 011ab96d2cfc58d32f8fb38407d197b339ffd921 @Parameters public static Collection data() {
private BigDecimal validationAverage, validationLastPurchase, validationNominal, validationInputQuantity, validationOrderQuantity, validationExpectedResult; private BigDecimal validationCostForNumber; @Parameters public static Collection data() {
public static Collection data() { return Arrays.asList(new Object[][] { // mode, average, lastPurchase, nominal, costForNumber, input qtty, order qtty, expectedResult <<<<<<< HEAD { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(1), valueOf(1), valueOf(30) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(2), valueOf(1), valueOf(60) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(3), valueOf(1), valueOf(90) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(3), valueOf(2), valueOf(180) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(3), valueOf(3), valueOf(270) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(3), valueOf(4), valueOf(360) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(2), valueOf(3), valueOf(2), valueOf(90) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(2), valueOf(3), valueOf(3), valueOf(135) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(2), valueOf(3), valueOf(4), valueOf(180) }, }); } public ParameterizedProductsCostCalculationServiceTest(ProductsCostCalculationConstants mode, BigDecimal average, BigDecimal lastPurchase, BigDecimal nominal, BigDecimal costForNumber, BigDecimal inputQuantity, ======= { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 1, valueOf(1), valueOf(1), valueOf(30) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 1, valueOf(2), valueOf(1), valueOf(60) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 1, valueOf(3), valueOf(1), valueOf(90) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 1, valueOf(3), valueOf(2), valueOf(180) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 1, valueOf(3), valueOf(3), valueOf(270) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 1, valueOf(3), valueOf(4), valueOf(360) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 2, valueOf(3), valueOf(2), valueOf(90) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 2, valueOf(3), valueOf(3), valueOf(135) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), 2, valueOf(3), valueOf(4), valueOf(180) }, }); } public ParameterizedProductsCostCalculationServiceTest(ProductsCostCalculationConstants mode, BigDecimal average, BigDecimal lastPurchase, BigDecimal nominal, Integer costForNumber, BigDecimal inputQuantity, >>>>>>> 011ab96d2cfc58d32f8fb38407d197b339ffd921 BigDecimal orderQuantity, BigDecimal expectedResult) { this.validationAverage = average; this.validationExpectedResult = expectedResult;
public static Collection data() { return Arrays.asList(new Object[][] { // mode, average, lastPurchase, nominal, costForNumber, input qtty, order qtty, expectedResult { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(1), valueOf(1), valueOf(30) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(2), valueOf(1), valueOf(60) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(3), valueOf(1), valueOf(90) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(3), valueOf(2), valueOf(180) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(3), valueOf(3), valueOf(270) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(1), valueOf(3), valueOf(4), valueOf(360) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(2), valueOf(3), valueOf(2), valueOf(90) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(2), valueOf(3), valueOf(3), valueOf(135) }, { AVERAGE, valueOf(10), valueOf(5), valueOf(15), valueOf(2), valueOf(3), valueOf(4), valueOf(180) }, }); } public ParameterizedProductsCostCalculationServiceTest(ProductsCostCalculationConstants mode, BigDecimal average, BigDecimal lastPurchase, BigDecimal nominal, BigDecimal costForNumber, BigDecimal inputQuantity, BigDecimal orderQuantity, BigDecimal expectedResult) { this.validationAverage = average; this.validationExpectedResult = expectedResult;
Entity inputProduct = mock(Entity.class); Entity product = mock(Entity.class); <<<<<<< HEAD Iterator operationComponentsIterator = mock(Iterator.class); when(operationComponentsIterator.hasNext()).thenReturn(true, false); when(operationComponentsIterator.next()).thenReturn(operationComponent); when(operationComponents.iterator()).thenReturn(operationComponentsIterator); Iterator inputProductsIterator = mock(Iterator.class); when(inputProductsIterator.hasNext()).thenReturn(true, true, true, false); when(inputProductsIterator.next()).thenReturn(inputProduct); when(inputProducts.iterator()).thenReturn(inputProductsIterator); when(technology.getTreeField("operationComponents")).thenReturn(operationComponents); when(operationComponent.getHasManyField("operationProductInComponents")).thenReturn(inputProducts); ======= when(technology.getTreeField("operationComponents")).thenReturn(operationComponents); when(operationComponents.size()).thenReturn(3); when(operationComponents.isEmpty()).thenReturn(false); when(operationComponents.get(lt(3))).thenReturn(operationComponent); when(operationComponent.getHasManyField("operationProductInComponents")).thenReturn(inputProducts); when(inputProducts.get(0)).thenReturn(inputProduct); when(inputProducts.get(1)).thenReturn(inputProduct); when(inputProducts.get(2)).thenReturn(inputProduct); >>>>>>> 011ab96d2cfc58d32f8fb38407d197b339ffd921 when(inputProduct.getField("quantity")).thenReturn(validationInputQuantity); when(inputProduct.getBelongsToField("product")).thenReturn(product);
Entity inputProduct = mock(Entity.class); Entity product = mock(Entity.class); Iterator operationComponentsIterator = mock(Iterator.class); when(operationComponentsIterator.hasNext()).thenReturn(true, false); when(operationComponentsIterator.next()).thenReturn(operationComponent); when(operationComponents.iterator()).thenReturn(operationComponentsIterator); Iterator inputProductsIterator = mock(Iterator.class); when(inputProductsIterator.hasNext()).thenReturn(true, true, true, false); when(inputProductsIterator.next()).thenReturn(inputProduct); when(inputProducts.iterator()).thenReturn(inputProductsIterator); when(technology.getTreeField("operationComponents")).thenReturn(operationComponents); when(operationComponent.getHasManyField("operationProductInComponents")).thenReturn(inputProducts); when(inputProduct.getField("quantity")).thenReturn(validationInputQuantity); when(inputProduct.getBelongsToField("product")).thenReturn(product);
Map result = productCostCalc.calculateProductsCost(technology, validationMode, validationOrderQuantity); <<<<<<< HEAD // // then assertEquals(validationExpectedResult, result.get("materialCost")); } ======= // then assertEquals(validationExpectedResult, result.get("materialCost")); } */ >>>>>>> 011ab96d2cfc58d32f8fb38407d197b339ffd921 }
Map result = productCostCalc.calculateProductsCost(technology, validationMode, validationOrderQuantity); // // then assertEquals(validationExpectedResult, result.get("materialCost")); } }