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

vertx.effect.mock.ValMock Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
package vertx.effect.mock;

import io.vertx.core.Future;
import vertx.effect.Val;
import vertx.effect.exp.Cons;

import java.util.Objects;
import java.util.function.IntFunction;
import java.util.function.Supplier;

public class ValMock implements Supplier> {

    private int counter;
    private final IntFunction getValue;
    private final Val val;


    public ValMock(final IntFunction getValue) {

        this.getValue = Objects.requireNonNull(getValue);
        this.val = Cons.of(() -> {
                               counter += 1;
                               return Future.succeededFuture(getValue.apply(counter));
                           }
                          );
    }


    @Override
    public Val get() {
        //danger zone, counter is mutable, we have to return a brand new instance
        return new ValMock<>(getValue).val;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy