use of com.vaadin.flow.function.SerializableRunnable in project flow by vaadin.
the class UITest method accessLaterRunnable_detachedUi_detachHandlerCalled.
@Test
public void accessLaterRunnable_detachedUi_detachHandlerCalled() {
AtomicInteger runCount = new AtomicInteger();
UI ui = createTestUI();
SerializableRunnable wrapped = ui.accessLater(() -> Assert.fail("Action should never run"), runCount::incrementAndGet);
assertEquals("Handler should not yet have run", 0, runCount.get());
wrapped.run();
assertEquals("Handler should have run once", 1, runCount.get());
}
use of com.vaadin.flow.function.SerializableRunnable in project flow by vaadin.
the class UITest method accessLaterRunnable_detachedUiNoHandler_throws.
@Test(expected = UIDetachedException.class)
public void accessLaterRunnable_detachedUiNoHandler_throws() {
UI ui = createTestUI();
SerializableRunnable wrapped = ui.accessLater(() -> Assert.fail("Action should never run"), null);
wrapped.run();
}
use of com.vaadin.flow.function.SerializableRunnable in project flow by vaadin.
the class UITest method accessLaterRunnable_attachedUnlockedUi_runnableIsRun.
@Test
public void accessLaterRunnable_attachedUnlockedUi_runnableIsRun() {
AtomicInteger runCount = new AtomicInteger();
UI ui = createAccessableTestUI();
CurrentInstance.clearAll();
SerializableRunnable wrapped = ui.accessLater(() -> {
assertSame("Current UI should be defined", ui, UI.getCurrent());
runCount.incrementAndGet();
}, null);
assertNull("Should not have a current UI outside the caller", UI.getCurrent());
assertEquals("Task should not yet have run", 0, runCount.get());
wrapped.run();
assertNull("Should not have a current UI outside the caller", UI.getCurrent());
assertEquals("Task should have run once", 1, runCount.get());
}
use of com.vaadin.flow.function.SerializableRunnable in project flow by vaadin.
the class AbstractSinglePropertyFieldTest method synchronizedEvent_null_noSynchronization.
@Test
public void synchronizedEvent_null_noSynchronization() {
StringField stringField = new StringField();
SerializableRunnable unregisterListener = Mockito.mock(SerializableRunnable.class);
stringField.getSynchronizationRegistration().onUnregister(unregisterListener);
stringField.setSynchronizedEvent(null);
Assert.assertNull(stringField.getSynchronizationRegistration());
Mockito.verify(unregisterListener).run();
}
use of com.vaadin.flow.function.SerializableRunnable in project flow by vaadin.
the class AbstractSinglePropertyFieldTest method synchronizedEvent_redefined.
@Test
public void synchronizedEvent_redefined() {
StringField stringField = new StringField();
DomListenerRegistration origReg = stringField.getSynchronizationRegistration();
SerializableRunnable unregisterListener = Mockito.mock(SerializableRunnable.class);
origReg.onUnregister(unregisterListener);
stringField.setSynchronizedEvent("blur");
DomListenerRegistration recentReg = stringField.getSynchronizationRegistration();
Mockito.verify(unregisterListener).run();
Assert.assertNotSame(origReg, recentReg);
Assert.assertEquals("blur", recentReg.getEventType());
}
Aggregations