private EntityTreeNode mockOperationComponent( final Long id, final String nodeNumber, final Collection<Entity> inputProducts, final Collection<Entity> outputProducts, final List<EntityTreeNode> subOperations) { EntityTreeNode operationComponent = mock(EntityTreeNode.class); given(operationComponent.getId()).willReturn(id); EntityList inputProductsList = mockProductComponentsList(inputProducts); given(operationComponent.getHasManyField(OPERATION_PRODUCT_IN_COMPONENTS)) .willReturn(inputProductsList); given(operationComponent.getField(OPERATION_PRODUCT_IN_COMPONENTS)) .willReturn(inputProductsList); EntityList outputProductsList = mockProductComponentsList(outputProducts); given(operationComponent.getHasManyField(OPERATION_PRODUCT_OUT_COMPONENTS)) .willReturn(outputProductsList); given(operationComponent.getField(OPERATION_PRODUCT_OUT_COMPONENTS)) .willReturn(outputProductsList); given(operationComponent.getField(NODE_NUMBER)).willReturn(nodeNumber); given(operationComponent.getStringField(NODE_NUMBER)).willReturn(nodeNumber); given(operationComponent.getChildren()).willReturn(subOperations); return operationComponent; }
@Test public final void shouldReturnNotEmptyMapIfManyParentOpConsumesManyOutputsFromOneSubOp() { // given Entity product1 = mockProductComponent(1L); Entity product2 = mockProductComponent(2L); Entity product3 = mockProductComponent(3L); Entity product4 = mockProductComponent(4L); Entity product5 = mockProductComponent(5L); Entity product6 = mockProductComponent(6L); Entity product7 = mockProductComponent(7L); Entity product8 = mockProductComponent(8L); Entity product9 = mockProductComponent(9L); Entity product10 = mockProductComponent(10L); Entity product11 = mockProductComponent(11L); Entity product12 = mockProductComponent(12L); EntityTreeNode node1A3 = mockOperationComponent( "1.A.3.", newArrayList(product11, product12), newArrayList(product10)); EntityTreeNode node1A2 = mockOperationComponent( "1.A.2.", newArrayList(product10), newArrayList(product7, product8, product9), newArrayList(node1A3)); EntityTreeNode node1A1 = mockOperationComponent( "1.A.1.", newArrayList(product7, product8, product9), newArrayList(product2, product3), newArrayList(node1A2)); EntityTreeNode node1B1 = mockOperationComponent("1.B.1.", newArrayList(product6), newArrayList(product4, product5)); EntityTreeNode node1 = mockOperationComponent( "1.", newArrayList(product2, product3, product4, product5), newArrayList(product1), newArrayList(node1A1, node1B1)); given(tree.getRoot()).willReturn(node1); // when resultMap = technologyTreeValidationService.checkConsumingManyProductsFromOneSubOp(tree); // then assertNotNull(resultMap); assertFalse(resultMap.isEmpty()); assertEquals(2, resultMap.size()); assertEquals(2, resultMap.get(node1.getStringField(NODE_NUMBER)).size()); hasNodeNumbersFor(node1, node1A1); hasNodeNumbersFor(node1, node1B1); hasNodeNumbersFor(node1A1, node1A2); }