Skip to content

Package: TableViewerSWTBuilder_PTest

TableViewerSWTBuilder_PTest

nameinstructionbranchcomplexitylinemethod
TableViewerSWTBuilder_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%
columnRegexFilter()
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%
columnSubstringFilter()
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%
constant(Object)
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%
constant(Object, Object)
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%
createFixture()
M: 0 C: 15
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: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
showHideColumns()
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%

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:
20: import java.util.Set;
21:
22: import org.eclipse.core.databinding.observable.Observables;
23: import org.eclipse.core.databinding.observable.Realm;
24: import org.eclipse.core.databinding.observable.list.IObservableList;
25: import org.eclipse.core.databinding.observable.value.IObservableValue;
26: import org.eclipse.emfforms.common.Feature;
27: import org.eclipse.swt.widgets.Composite;
28: import org.junit.Before;
29: import org.junit.Test;
30: import org.junit.runner.RunWith;
31: import org.mockito.Mock;
32: import org.mockito.runners.MockitoJUnitRunner;
33:
34: /**
35: * Unit tests for the {@link TableViewerSWTBuilder} class.
36: */
37: @SuppressWarnings("nls")
38: @RunWith(MockitoJUnitRunner.class)
39: public class TableViewerSWTBuilder_PTest {
40:
41:         @Mock
42:         private Composite parent;
43:
44:         @Mock
45:         private IObservableList<?> input;
46:
47:         private TableViewerSWTBuilder fixture;
48:
49:         /**
50:          * Initializes me.
51:          */
52:         public TableViewerSWTBuilder_PTest() {
53:                 super();
54:         }
55:
56:         @Test
57:         public void showHideColumns() {
58:                 fixture.showHideColumns(true);
59:                 assertThat("show/hide feature not enabled", enabledFeatures(),
60:                         hasItem(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW));
61:                 fixture.showHideColumns(false);
62:                 assertThat("show/hide feature still enabled", enabledFeatures(),
63:                         not(hasItem(TableConfiguration.FEATURE_COLUMN_HIDE_SHOW)));
64:         }
65:
66:         @Test
67:         public void columnSubstringFilter() {
68:                 fixture.columnSubstringFilter(true);
69:                 assertThat("filter feature not enabled", enabledFeatures(), hasItem(TableConfiguration.FEATURE_COLUMN_FILTER));
70:                 fixture.columnSubstringFilter(false);
71:                 assertThat("filter feature still enabled", enabledFeatures(),
72:                         not(hasItem(TableConfiguration.FEATURE_COLUMN_FILTER)));
73:         }
74:
75:         @Test
76:         public void columnRegexFilter() {
77:                 fixture.columnRegexFilter(true);
78:                 assertThat("regex filter feature not enabled", enabledFeatures(),
79:                         hasItem(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER));
80:                 fixture.columnRegexFilter(false);
81:                 assertThat("regex filter feature still enabled", enabledFeatures(),
82:                         not(hasItem(TableConfiguration.FEATURE_COLUMN_REGEX_FILTER)));
83:         }
84:
85:         //
86:         // Test framework
87:         //
88:
89:         @Before
90:         public void createFixture() {
91:                 fixture = new TableViewerSWTBuilder(parent, 0, input, constant("title"), constant("tooltip"));
92:         }
93:
94:         /**
95:          * Like {@link Observables#constantObservableValue(Object, Object)} except with the correct
96:          * generic signature.
97:          *
98:          * @see <a href="http://eclip.se/512630">bug 512630</a>
99:          */
100:         static <T> IObservableValue<T> constant(T value, Object type) {
101:                 return Observables.constantObservableValue(Realm.getDefault(), value, type);
102:         }
103:
104:         static <T> IObservableValue<T> constant(T value) {
105:                 return constant(value, value.getClass());
106:         }
107:
108:         @SuppressWarnings("deprecation")
109:         Set<Feature> enabledFeatures() {
110:                 return fixture.getEnabledFeatures();
111:         }
112:
113: }