|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to you under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.hop.ui.core.gui; |
| 18 | + |
| 19 | +import static org.mockito.Mockito.mock; |
| 20 | +import static org.mockito.Mockito.never; |
| 21 | +import static org.mockito.Mockito.verify; |
| 22 | +import static org.mockito.Mockito.when; |
| 23 | + |
| 24 | +import java.util.Map; |
| 25 | +import org.apache.hop.ui.hopgui.file.IHopFileType; |
| 26 | +import org.eclipse.swt.widgets.MenuItem; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +class GuiMenuWidgetsDisposedTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + void ignoresDisposedMenuItemWhenUpdatingCapability() { |
| 33 | + String id = "file-save"; |
| 34 | + String permission = "save"; |
| 35 | + IHopFileType fileType = mock(IHopFileType.class); |
| 36 | + MenuItem menuItem = mock(MenuItem.class); |
| 37 | + when(fileType.hasCapability(permission)).thenReturn(true); |
| 38 | + when(menuItem.isDisposed()).thenReturn(true); |
| 39 | + |
| 40 | + GuiMenuWidgets widgets = new GuiMenuWidgets(); |
| 41 | + widgets.setMenuItemMap(Map.of(id, menuItem)); |
| 42 | + |
| 43 | + widgets.enableMenuItem(fileType, id, permission); |
| 44 | + |
| 45 | + verify(menuItem, never()).isEnabled(); |
| 46 | + verify(menuItem, never()).setEnabled(true); |
| 47 | + } |
| 48 | +} |
0 commit comments