Search in sources :

Example 1 with SerializableRunnable

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());
}
Also used : MockUI(com.vaadin.tests.util.MockUI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializableRunnable(com.vaadin.flow.function.SerializableRunnable) BootstrapHandlerTest(com.vaadin.flow.server.BootstrapHandlerTest) Test(org.junit.Test)

Example 2 with SerializableRunnable

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();
}
Also used : MockUI(com.vaadin.tests.util.MockUI) SerializableRunnable(com.vaadin.flow.function.SerializableRunnable) BootstrapHandlerTest(com.vaadin.flow.server.BootstrapHandlerTest) Test(org.junit.Test)

Example 3 with SerializableRunnable

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());
}
Also used : MockUI(com.vaadin.tests.util.MockUI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializableRunnable(com.vaadin.flow.function.SerializableRunnable) BootstrapHandlerTest(com.vaadin.flow.server.BootstrapHandlerTest) Test(org.junit.Test)

Example 4 with SerializableRunnable

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();
}
Also used : SerializableRunnable(com.vaadin.flow.function.SerializableRunnable) Test(org.junit.Test)

Example 5 with SerializableRunnable

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());
}
Also used : SerializableRunnable(com.vaadin.flow.function.SerializableRunnable) DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration) Test(org.junit.Test)

Aggregations

SerializableRunnable (com.vaadin.flow.function.SerializableRunnable)5 Test (org.junit.Test)5 BootstrapHandlerTest (com.vaadin.flow.server.BootstrapHandlerTest)3 MockUI (com.vaadin.tests.util.MockUI)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DomListenerRegistration (com.vaadin.flow.dom.DomListenerRegistration)1