All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smallrye.mutiny.test.Mocks Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
package io.smallrye.mutiny.test;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;

import java.util.concurrent.Flow.Subscriber;
import java.util.concurrent.Flow.Subscription;

import org.mockito.Mockito;

public class Mocks {

    /**
     * Mocks a subscriber and prepares it to request {@code Long.MAX_VALUE}.
     *
     * @param  the value type
     * @return the mocked subscriber
     */
    public static  Subscriber subscriber() {
        return subscriber(Long.MAX_VALUE);
    }

    /**
     * Mocks a subscriber and prepares it to request {@code req}.
     *
     * @param  the value type
     * @return the mocked subscriber
     */
    @SuppressWarnings("unchecked")
    public static  Subscriber subscriber(long req) {
        Subscriber subscriber = mock(Subscriber.class);
        Mockito.doAnswer(invocation -> {
            Subscription subscription = invocation.getArgument(0, Subscription.class);
            if (req != 0) {
                subscription.request(req);
            }
            return null;
        }).when(subscriber).onSubscribe(any(Subscription.class));
        return subscriber;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy