1+ package checkmarx .ast .eclipse .plugin .tests .unit ;
2+
3+ import static org .junit .jupiter .api .Assertions .*;
4+ import static org .mockito .Mockito .*;
5+
6+ import java .util .Collections ;
7+ import java .util .List ;
8+
9+ import org .eclipse .jface .action .Action ;
10+ import org .eclipse .jface .action .IMenuManager ;
11+ import org .eclipse .jface .action .IToolBarManager ;
12+ import org .eclipse .jface .viewers .ComboViewer ;
13+ import org .eclipse .jface .viewers .TreeViewer ;
14+ import org .eclipse .ui .IActionBars ;
15+ import org .junit .jupiter .api .BeforeEach ;
16+ import org .junit .jupiter .api .Test ;
17+ import org .mockito .Mockito ;
18+
19+ import com .checkmarx .eclipse .enums .PluginListenerType ;
20+ import com .checkmarx .eclipse .views .DisplayModel ;
21+ import com .checkmarx .eclipse .views .PluginListenerDefinition ;
22+ import com .checkmarx .eclipse .views .actions .ToolBarActions ;
23+ import com .checkmarx .eclipse .views .filters .FilterState ;
24+ import com .google .common .eventbus .EventBus ;
25+
26+ class ToolBarActionsTest {
27+
28+ private IActionBars actionBars ;
29+ private IToolBarManager toolBarManager ;
30+ private IMenuManager menuManager ;
31+
32+ private TreeViewer resultsTree ;
33+ private ComboViewer projectCombo ;
34+ private ComboViewer branchCombo ;
35+ private ComboViewer scanCombo ;
36+
37+ private EventBus eventBus ;
38+ private DisplayModel rootModel ;
39+
40+ private ToolBarActions toolBarActions ;
41+
42+ @ BeforeEach
43+ void setup () {
44+
45+ actionBars = mock (IActionBars .class );
46+ toolBarManager = mock (IToolBarManager .class );
47+ menuManager = mock (IMenuManager .class );
48+
49+ resultsTree = mock (TreeViewer .class );
50+ projectCombo = mock (ComboViewer .class );
51+ branchCombo = mock (ComboViewer .class );
52+ scanCombo = mock (ComboViewer .class );
53+
54+ rootModel = mock (DisplayModel .class );
55+ eventBus = new EventBus ();
56+
57+ when (actionBars .getToolBarManager ()).thenReturn (toolBarManager );
58+ when (actionBars .getMenuManager ()).thenReturn (menuManager );
59+
60+ toolBarActions =
61+ new ToolBarActions .ToolBarActionsBuilder ()
62+ .actionBars (actionBars )
63+ .rootModel (rootModel )
64+ .resultsTree (resultsTree )
65+ .pluginEventBus (eventBus )
66+ .projectsCombo (projectCombo )
67+ .branchesCombo (branchCombo )
68+ .scansCombo (scanCombo )
69+ .build ();
70+ }
71+
72+ @ Test
73+ void testBuilderCreatesInstance () {
74+ assertNotNull (toolBarActions );
75+ }
76+
77+ @ Test
78+ void testGetToolBarActions () {
79+ List <Action > actions = toolBarActions .getToolBarActions ();
80+ assertNotNull (actions );
81+ }
82+
83+ @ Test
84+ void testGetFilterActions () {
85+ List <Action > filters = toolBarActions .getFilterActions ();
86+ assertNotNull (filters );
87+ }
88+
89+ @ Test
90+ void testGetStartScanAction () {
91+ Action action = toolBarActions .getStartScanAction ();
92+ assertNotNull (action );
93+ }
94+
95+ @ Test
96+ void testGetCancelScanAction () {
97+ Action action = toolBarActions .getCancelScanAction ();
98+ assertNotNull (action );
99+ }
100+
101+ @ Test
102+ void testGetStateFilterAction () {
103+ Action action = toolBarActions .getStateFilterAction ();
104+ assertNotNull (action );
105+ }
106+
107+ @ Test
108+ void testDisposeToolbarRemovesAll () {
109+
110+ toolBarActions .disposeToolbar ();
111+
112+ verify (toolBarManager ).removeAll ();
113+ verify (menuManager ).removeAll ();
114+ }
115+
116+ @ Test
117+ void testRefreshToolbarRecreatesActions () {
118+
119+ toolBarActions .refreshToolbar ();
120+
121+ verify (toolBarManager ).removeAll ();
122+ verify (menuManager ).removeAll ();
123+ }
124+
125+ @ Test
126+ void testGroupBySeverityAction () {
127+
128+ List <Action > actions = toolBarActions .getFilterActions ();
129+
130+ for (Action action : actions ) {
131+ if ("GROUP_BY_SEVERITY" .equals (action .getId ())) {
132+ action .run ();
133+ break ;
134+ }
135+ }
136+
137+ assertTrue (FilterState .groupBySeverity );
138+ }
139+
140+ @ Test
141+ void testEventBusPostCleanRefresh () {
142+
143+ assertDoesNotThrow (() -> {
144+ eventBus .post (
145+ new PluginListenerDefinition (
146+ PluginListenerType .CLEAN_AND_REFRESH ,
147+ Collections .emptyList ()));
148+ });
149+ }
150+
151+ @ Test
152+ void testBuilderSetsComboViewers () {
153+
154+ ToolBarActions actions =
155+ new ToolBarActions .ToolBarActionsBuilder ()
156+ .actionBars (actionBars )
157+ .rootModel (rootModel )
158+ .resultsTree (resultsTree )
159+ .pluginEventBus (eventBus )
160+ .projectsCombo (projectCombo )
161+ .branchesCombo (branchCombo )
162+ .scansCombo (scanCombo )
163+ .build ();
164+
165+ assertNotNull (actions );
166+ }
167+
168+ @ Test
169+ void testToolBarActionsListNotEmpty () {
170+
171+ List <Action > actions = toolBarActions .getToolBarActions ();
172+
173+ assertNotNull (actions );
174+ assertTrue (actions .size () >= 0 );
175+ }
176+
177+ }
0 commit comments