Skip to content

Package: CategoryItemProvider_Test

CategoryItemProvider_Test

nameinstructionbranchcomplexitylinemethod
CategoryItemProvider_Test()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setUp()
M: 0 C: 65
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
testCollectContainerChildDecriptors()
M: 0 C: 44
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testCollectNewChildDescriptors()
M: 3 C: 63
95%
M: 5 C: 7
58%
M: 5 C: 2
29%
M: 1 C: 15
94%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.categorization.model.provider;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertTrue;
18: import static org.junit.Assert.fail;
19: import static org.mockito.Matchers.any;
20: import static org.mockito.Matchers.isA;
21: import static org.mockito.Mockito.mock;
22: import static org.mockito.Mockito.verify;
23: import static org.mockito.Mockito.when;
24:
25: import java.util.Collection;
26: import java.util.LinkedList;
27: import java.util.List;
28:
29: import org.eclipse.emf.common.notify.AdapterFactory;
30: import org.eclipse.emf.ecore.EObject;
31: import org.eclipse.emf.ecp.common.spi.ChildrenDescriptorCollector;
32: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationFactory;
33: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationPackage;
34: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategory;
35: import org.eclipse.emf.ecp.view.spi.model.VAttachment;
36: import org.eclipse.emf.ecp.view.spi.model.VContainer;
37: import org.eclipse.emf.ecp.view.spi.model.VElement;
38: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
39: import org.eclipse.emf.edit.command.CommandParameter;
40: import org.junit.Before;
41: import org.junit.Test;
42:
43: /**
44: * Unit tests for the {@link CategoryItemProvider}.
45: *
46: * @author Lucas Koehler
47: *
48: */
49: public class CategoryItemProvider_Test {
50:
51:         private TestCategoryItemProvider provider;
52:         private ChildrenDescriptorCollector collector;
53:         private VElement parameterElement;
54:
55:         @Before
56:         @SuppressWarnings({ "rawtypes", "unchecked" })
57:         public void setUp() {
58:                 provider = new TestCategoryItemProvider(mock(AdapterFactory.class));
59:                 final Collection descriptors = new LinkedList();
60:                 parameterElement = mock(VElement.class);
61:                 final VAttachment attachment = mock(VAttachment.class);
62:                 final CommandParameter parameter = new CommandParameter(null, VViewPackage.Literals.CONTAINER__CHILDREN,
63:                         parameterElement);
64:                 final CommandParameter filteredParameter = new CommandParameter(null,
65:                         VViewPackage.Literals.ELEMENT__ATTACHMENTS, attachment);
66:                 descriptors.add(parameter);
67:                 descriptors.add(filteredParameter);
68:                 collector = mock(ChildrenDescriptorCollector.class);
69:                 when(collector.getDescriptors(any(EObject.class))).thenReturn(descriptors);
70:                 provider.setChildrenDescriptorCollector(collector);
71:
72:         }
73:
74:         @Test
75:         public void testCollectNewChildDescriptors() {
76:                 final List<Object> result = new LinkedList<Object>();
77:                 final VCategory category = VCategorizationFactory.eINSTANCE.createCategory();
78:                 provider.collectNewChildDescriptors(result, category);
79:
80:                 verify(collector).getDescriptors(isA(VContainer.class));
81:•                assertTrue(result.size() >= 1);
82:
83:                 /*
84:                  * Verify that the result contains the command parameter retrieved by the collectContainerChildDecriptors().
85:                  * Cannot verify that #collectContainerChildDecriptors was called because using Mockito.spy does not work
86:                  * properly with the TestCategoryItemProvider.
87:                  */
88:                 boolean resultContainsResult = false;
89:•                for (final Object object : result) {
90:•                        if (object instanceof CommandParameter) {
91:                                 final CommandParameter p = (CommandParameter) object;
92:•                                if (parameterElement.equals(p.getValue())
93:•                                        && VCategorizationPackage.Literals.CATEGORY__COMPOSITE.equals(p.getFeature())) {
94:                                         resultContainsResult = true;
95:                                         break;
96:                                 }
97:                         }
98:                 }
99:•                if (!resultContainsResult) {
100:                         fail("The result did not contain the CommandParameter returned by #collectContainerChildDescriptors.");
101:                 }
102:         }
103:
104:         @Test
105:         public void testCollectContainerChildDecriptors() {
106:                 final List<Object> result = new LinkedList<Object>();
107:                 provider.collectContainerChildDecriptors(result, VCategorizationFactory.eINSTANCE.createCategory());
108:
109:                 // Verify that only a command parameter for VContainer's children reference was added and that it was correctly
110:                 // adapted to the VCategory.
111:                 assertEquals(1, result.size());
112:                 assertTrue(result.get(0) instanceof CommandParameter);
113:                 final CommandParameter p = (CommandParameter) result.get(0);
114:                 assertEquals(parameterElement, p.getValue());
115:                 assertEquals(VCategorizationPackage.Literals.CATEGORY__COMPOSITE, p.getFeature());
116:                 // Need to get the child descriptors from the ChildrenDescriptorCollector for an implementation of VContainer.
117:                 verify(collector).getDescriptors(isA(VContainer.class));
118:
119:         }
120: }