/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.sal.restconf.impl.test; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.opendaylight.yangtools.yang.common.RpcResult; public class DummyFuture implements Future> { private final boolean cancel; private final boolean isCancelled; private final boolean isDone; private final RpcResult result; public DummyFuture() { cancel = false; isCancelled = false; isDone = false; result = null; } private DummyFuture(final Builder builder) { cancel = builder.cancel; isCancelled = builder.isCancelled; isDone = builder.isDone; result = builder.result; } @Override public boolean cancel(final boolean mayInterruptIfRunning) { return cancel; } @Override public boolean isCancelled() { return isCancelled; } @Override public boolean isDone() { return isDone; } @Override public RpcResult get() throws InterruptedException, ExecutionException { return result; } @Override public RpcResult get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return result; } public static class Builder { private boolean cancel; private boolean isCancelled; private boolean isDone; private RpcResult result; public Builder cancel(final boolean newCancel) { this.cancel = newCancel; return this; } public Builder isCancelled(final boolean cancelled) { this.isCancelled = cancelled; return this; } public Builder isDone(final boolean done) { this.isDone = done; return this; } public Builder rpcResult(final RpcResult newResult) { this.result = newResult; return this; } public Future> build() { return new DummyFuture<>(this); } } }