Skip to content

Package: ColumnConfigurationBuilder_PTest

ColumnConfigurationBuilder_PTest

nameinstructionbranchcomplexitylinemethod
ColumnConfigurationBuilder_PTest()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createFixture()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
enabledFeatures()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
from_TableViewerSWTBuilder()
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
regexFilter()
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
showHide()
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
substringFilter()
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.table;
15:
16: import static org.hamcrest.CoreMatchers.hasItem;
17: import static org.hamcrest.CoreMatchers.not;
18: import static org.junit.Assert.assertThat;
19: import static org.mockito.Mockito.mock;
20:
21: import java.util.Set;
22:
23: import org.eclipse.core.databinding.observable.list.IObservableList;
24: import org.eclipse.emfforms.common.Feature;
25: import org.eclipse.swt.widgets.Composite;
26: import org.junit.Before;
27: import org.junit.Test;
28:
29: /**
30: * Unit tests for the {@link ColumnConfigurationBuilder} class.
31: */
32: @SuppressWarnings("nls")
33: public class ColumnConfigurationBuilder_PTest {
34:
35:         private ColumnConfigurationBuilder fixture;
36:
37:         /**
38:          * Initializes me.
39:          */
40:         public ColumnConfigurationBuilder_PTest() {
41:                 super();
42:         }
43:
44:         @Test
45:         public void showHide() {
46:                 fixture.showHide(true);
47:                 assertThat("show/hide feature not enabled", enabledFeatures(),
48:                         hasItem(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW));
49:                 fixture.showHide(false);
50:                 assertThat("show/hide feature still enabled", enabledFeatures(),
51:                         not(hasItem(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW)));
52:         }
53:
54:         @Test
55:         public void substringFilter() {
56:                 fixture.substringFilter(true);
57:                 assertThat("filter feature not enabled", enabledFeatures(), hasItem(TableConfiguration.FEATURE_COLUMN_FILTER));
58:                 fixture.substringFilter(false);
59:                 assertThat("filter feature still enabled", enabledFeatures(),
60:                         not(hasItem(TableConfiguration.FEATURE_COLUMN_FILTER)));
61:         }
62:
63:         @Test
64:         public void regexFilter() {
65:                 fixture.regexFilter(true);
66:                 assertThat("regex filter feature not enabled", enabledFeatures(),
67:                         hasItem(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER));
68:                 fixture.regexFilter(false);
69:                 assertThat("regex filter feature still enabled", enabledFeatures(),
70:                         not(hasItem(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER)));
71:         }
72:
73:         @Test
74:         public void from_TableViewerSWTBuilder() {
75:                 final Composite parent = mock(Composite.class);
76:                 final IObservableList<?> input = mock(IObservableList.class);
77:                 final TableViewerSWTBuilder viewerBuilder = TableViewerFactory.fillDefaults(parent, 0, input);
78:
79:                 viewerBuilder.showHideColumns(true);
80:                 viewerBuilder.columnSubstringFilter(true);
81:                 viewerBuilder.columnRegexFilter(true);
82:
83:                 fixture = ColumnConfigurationBuilder.from(viewerBuilder);
84:
85:                 assertThat("show/hide feature not enabled", enabledFeatures(),
86:                         hasItem(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW));
87:                 assertThat("filter feature not enabled", enabledFeatures(), hasItem(TableConfiguration.FEATURE_COLUMN_FILTER));
88:                 assertThat("regex filter feature not enabled", enabledFeatures(),
89:                         hasItem(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER));
90:         }
91:
92:         //
93:         // Test framework
94:         //
95:
96:         @Before
97:         public void createFixture() {
98:                 fixture = ColumnConfigurationBuilder.usingDefaults();
99:         }
100:
101:         Set<Feature> enabledFeatures() {
102:                 return fixture.build().getEnabledFeatures();
103:         }
104:
105: }