Package org.fotap.heysync

Source Code of org.fotap.heysync.LatestOnlyTest

package org.fotap.heysync;

import org.jetlang.fibers.FiberStub;
import org.junit.Test;

import static org.mockito.Mockito.*;

public class LatestOnlyTest {

    @Test
    public void shouldExecuteCallbackWithMostRecentValue() throws Exception {
        InvokedFrequently subscription = mock(InvokedFrequently.class);

        Protocol<InvokedFrequently> protocol = Protocol.create(InvokedFrequently.class);
        FiberStub fiberStub = new FiberStub();
        protocol.subscribe(fiberStub, subscription);
        protocol.publisher().calledFasterThanCanBeProcessed("one");
        protocol.publisher().calledFasterThanCanBeProcessed("two");
        protocol.publisher().calledFasterThanCanBeProcessed("three");
        protocol.publisher().calledFasterThanCanBeProcessed("four");

        fiberStub.executeAllPending();

        verify(subscription).calledFasterThanCanBeProcessed("four");
        verifyNoMoreInteractions(subscription);
    }
}
TOP

Related Classes of org.fotap.heysync.LatestOnlyTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.