Merge "Fixed for bug : 1171 - issue while creating subnet"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / DummyFuture.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.restconf.impl.test;
9
10 import java.util.concurrent.ExecutionException;
11 import java.util.concurrent.Future;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
14 import org.opendaylight.yangtools.yang.common.RpcResult;
15
16 public class DummyFuture<T> implements Future<RpcResult<T>> {
17
18     private final boolean cancel;
19     private final boolean isCancelled;
20     private final boolean isDone;
21     private final RpcResult<T> result;
22
23     public DummyFuture() {
24         cancel = false;
25         isCancelled = false;
26         isDone = false;
27         result = null;
28     }
29
30     private DummyFuture(final Builder<T> builder) {
31         cancel = builder.cancel;
32         isCancelled = builder.isCancelled;
33         isDone = builder.isDone;
34         result = builder.result;
35     }
36
37     @Override
38     public boolean cancel(final boolean mayInterruptIfRunning) {
39         return cancel;
40     }
41
42     @Override
43     public boolean isCancelled() {
44         return isCancelled;
45     }
46
47     @Override
48     public boolean isDone() {
49         return isDone;
50     }
51
52     @Override
53     public RpcResult<T> get() throws InterruptedException, ExecutionException {
54         return result;
55     }
56
57     @Override
58     public RpcResult<T> get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException,
59             TimeoutException {
60         return result;
61     }
62
63     public static class Builder<T> {
64
65         private boolean cancel;
66         private boolean isCancelled;
67         private boolean isDone;
68         private RpcResult<T> result;
69
70         public Builder<T> cancel(final boolean cancel) {
71             this.cancel = cancel;
72             return this;
73         }
74
75         public Builder<T> isCancelled(final boolean isCancelled) {
76             this.isCancelled = isCancelled;
77             return this;
78         }
79
80         public Builder<T> isDone(final boolean isDone) {
81             this.isDone = isDone;
82             return this;
83         }
84
85         public Builder<T> rpcResult(final RpcResult<T> result) {
86             this.result = result;
87             return this;
88         }
89
90         public Future<RpcResult<T>> build() {
91             return new DummyFuture<T>(this);
92         }
93     }
94 }