Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,8 +15,8 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -66,12 +66,7 @@ public void test_setTextLjava_lang_String() {
assertEquals("a", testStr, item.getText());
item.setText("");
assertTrue("b", item.getText().isEmpty());
try {
item.setText(null);
fail("No exception thrown for string == null");
}
catch (IllegalArgumentException e) {
}
assertThrows("No exception thrown for string == null", IllegalArgumentException.class, () -> item.setText(null));
}

/* custom */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -17,8 +17,8 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ArmListener;
Expand Down Expand Up @@ -52,12 +52,7 @@ public void test_ConstructorLorg_eclipse_swt_widgets_MenuI() {
MenuItem mItem = new MenuItem(menu, SWT.NULL);
assertNotNull(mItem);

try {
new MenuItem(null, SWT.NULL);
fail("No exception thrown");
}
catch (IllegalArgumentException e) {
}
assertThrows(IllegalArgumentException.class, () -> new MenuItem(null, SWT.NULL));
mItem = new MenuItem(menu, SWT.CHECK);
assertEquals(SWT.CHECK, mItem.getStyle());
mItem.dispose();
Expand Down Expand Up @@ -90,21 +85,15 @@ public void test_addArmListenerLorg_eclipse_swt_events_ArmListener() {
listenerCalled = false;
ArmListener listener = e -> listenerCalled = true;

try {
menuItem.addArmListener(null);
fail("No exception thrown for addArmListener with null argument");
} catch (IllegalArgumentException e) {
}
assertThrows("No exception thrown for addArmListener with null argument", IllegalArgumentException.class,
() -> menuItem.addArmListener(null));

menuItem.addArmListener(listener);
menuItem.notifyListeners(SWT.Arm, new Event());
assertTrue(listenerCalled);

try {
menuItem.removeArmListener(null);
fail("No exception thrown for removeArmListener with null argument");
} catch (IllegalArgumentException e) {
}
assertThrows("No exception thrown for removeArmListener with null argument", IllegalArgumentException.class,
() -> menuItem.removeArmListener(null));
listenerCalled = false;
menuItem.removeArmListener(listener);
menuItem.notifyListeners(SWT.Arm, new Event());
Expand All @@ -116,21 +105,15 @@ public void test_addHelpListenerLorg_eclipse_swt_events_HelpListener() {
listenerCalled = false;
HelpListener listener = e -> listenerCalled = true;

try {
menuItem.addHelpListener(null);
fail("No exception thrown for addHelpListener with null argument");
} catch (IllegalArgumentException e) {
}
assertThrows("No exception thrown for addHelpListener with null argument", IllegalArgumentException.class,
() -> menuItem.addHelpListener(null));

menuItem.addHelpListener(listener);
menuItem.notifyListeners(SWT.Help, new Event());
assertTrue(listenerCalled);

try {
menuItem.removeHelpListener(null);
fail("No exception thrown for removeHelpListener with null argument");
} catch (IllegalArgumentException e) {
}
assertThrows("No exception thrown for removeHelpListener with null argument", IllegalArgumentException.class,
() -> menuItem.removeHelpListener(null));
listenerCalled = false;
menuItem.removeHelpListener(listener);
menuItem.notifyListeners(SWT.Help, new Event());
Expand All @@ -150,21 +133,15 @@ public void widgetDefaultSelected(SelectionEvent e) {
}
};

try {
menuItem.addSelectionListener(null);
fail("No exception thrown for addSelectionListener with null argument");
} catch (IllegalArgumentException e) {
}
assertThrows("No exception thrown for addSelectionListener with null argument", IllegalArgumentException.class,
() -> menuItem.addSelectionListener(null));

menuItem.addSelectionListener(listener);
menuItem.notifyListeners(SWT.Selection, new Event());
assertTrue(listenerCalled);

try {
menuItem.removeSelectionListener(null);
fail("No exception thrown for removeSelectionListener with null argument");
} catch (IllegalArgumentException e) {
}
assertThrows("No exception thrown for removeSelectionListener with null argument", IllegalArgumentException.class,
() -> menuItem.removeSelectionListener(null));
listenerCalled = false;
menuItem.removeSelectionListener(listener);
menuItem.notifyListeners(SWT.Selection, new Event());
Expand Down Expand Up @@ -206,7 +183,7 @@ public void test_isEnabled() {
menuItem.setEnabled(true);
assertTrue(menuItem.isEnabled());
menuItem.setEnabled(false);
assertEquals(menuItem.isEnabled(), false);
assertFalse(menuItem.isEnabled());
}

@Test
Expand All @@ -220,7 +197,7 @@ public void test_setEnabledZ() {
menuItem.setEnabled(true);
assertTrue(menuItem.getEnabled());
menuItem.setEnabled(false);
assertEquals(menuItem.getEnabled(), false);
assertFalse(menuItem.getEnabled());
}

@Override
Expand Down Expand Up @@ -250,7 +227,7 @@ public void test_setSelectionZ() {
for (int itemStyle : itemStyles) {
MenuItem mItem = new MenuItem(menu, itemStyle);
mItem.setSelection(false);
assertEquals(mItem.getSelection(), false);
assertFalse(mItem.getSelection());
mItem.setSelection(true);
assertTrue(mItem.getSelection());
mItem.dispose();
Expand All @@ -262,11 +239,7 @@ public void test_setSelectionZ() {
public void test_setTextLjava_lang_String() {
menuItem.setText("ABCDEFG");
assertEquals("ABCDEFG", menuItem.getText());
try {
menuItem.setText(null);
fail("No exception thrown for addArmListener with null argument");
} catch (IllegalArgumentException e) {
}
assertThrows(IllegalArgumentException.class, () -> menuItem.setText(null));
menuItem.setText("ABCDEFG");
menuItem.setAccelerator(SWT.MOD1 + 'A');
assertTrue(menuItem.getText().startsWith("ABCDEFG"));
Expand Down
Loading