use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_Link method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.
@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
listenerCalled = false;
SelectionListener listener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
listenerCalled = true;
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
};
try {
link.addSelectionListener(null);
fail("No exception thrown for addSelectionListener with null argument");
} catch (IllegalArgumentException e) {
}
link.addSelectionListener(listener);
link.notifyListeners(SWT.Selection, new Event());
assertTrue(listenerCalled);
try {
link.removeSelectionListener(null);
fail("No exception thrown for removeSelectionListener with null argument");
} catch (IllegalArgumentException e) {
}
listenerCalled = false;
link.removeSelectionListener(listener);
link.notifyListeners(SWT.Selection, new Event());
assertFalse(listenerCalled);
}
use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_List method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.
@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
listenerCalled = false;
boolean exceptionThrown = false;
SelectionListener listener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent event) {
listenerCalled = true;
}
@Override
public void widgetDefaultSelected(SelectionEvent event) {
}
};
try {
list.addSelectionListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown for listener == null", exceptionThrown);
list.addSelectionListener(listener);
list.select(0);
assertFalse(":a:", listenerCalled);
list.removeSelectionListener(listener);
exceptionThrown = false;
try {
list.removeSelectionListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown for listener == null", exceptionThrown);
// test single-selection list
setSingleList();
listenerCalled = false;
exceptionThrown = false;
try {
list.addSelectionListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown for listener == null", exceptionThrown);
list.addSelectionListener(listener);
list.select(0);
assertFalse(":a:", listenerCalled);
list.removeSelectionListener(listener);
exceptionThrown = false;
try {
list.removeSelectionListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown for listener == null", exceptionThrown);
}
use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_MenuItem method test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener.
@Test
public void test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener() {
listenerCalled = false;
SelectionListener listener = SelectionListener.widgetSelectedAdapter(e -> listenerCalled = true);
menuItem.addSelectionListener(listener);
menuItem.notifyListeners(SWT.Selection, new Event());
assertTrue(listenerCalled);
listenerCalled = false;
menuItem.removeSelectionListener(listener);
menuItem.notifyListeners(SWT.Selection, new Event());
assertFalse(listenerCalled);
}
use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_ScrollBar method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.
@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
listenerCalled = false;
boolean exceptionThrown = false;
SelectionListener listener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent event) {
listenerCalled = true;
}
@Override
public void widgetDefaultSelected(SelectionEvent event) {
}
};
try {
scrollBar.addSelectionListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown", exceptionThrown);
exceptionThrown = false;
scrollBar.addSelectionListener(listener);
scrollBar.setSelection(100);
assertTrue(":a:", listenerCalled == false);
scrollBar.removeSelectionListener(listener);
try {
scrollBar.removeSelectionListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown", exceptionThrown);
}
use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_Slider method test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener.
@Test
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
listenerCalled = false;
boolean exceptionThrown = false;
SelectionListener listener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent event) {
listenerCalled = true;
}
@Override
public void widgetDefaultSelected(SelectionEvent event) {
}
};
try {
slider.addSelectionListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown", exceptionThrown);
exceptionThrown = false;
slider.addSelectionListener(listener);
slider.setSelection(0);
assertFalse(":a:", listenerCalled);
slider.removeSelectionListener(listener);
try {
slider.removeSelectionListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown", exceptionThrown);
}
Aggregations