Merge "BUG-614: introduce AbstractRuntimeCodeGenerator"
[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.*;
11
12 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
13 import org.opendaylight.yangtools.yang.common.RpcResult;
14
15 public class DummyFuture implements Future<RpcResult<TransactionStatus>> {
16
17     private final boolean cancel;
18     private final boolean isCancelled;
19     private final boolean isDone;
20     private final RpcResult<TransactionStatus> result;
21
22     public DummyFuture() {
23         cancel = false;
24         isCancelled = false;
25         isDone = false;
26         result = null;
27     }
28
29     private DummyFuture(Builder builder) {
30         cancel = builder.cancel;
31         isCancelled = builder.isCancelled;
32         isDone = builder.isDone;
33         result = builder.result;
34     }
35
36     public static Builder builder() {
37         return new DummyFuture.Builder();
38     }
39
40     @Override
41     public boolean cancel(boolean mayInterruptIfRunning) {
42         return cancel;
43     }
44
45     @Override
46     public boolean isCancelled() {
47         return isCancelled;
48     }
49
50     @Override
51     public boolean isDone() {
52         return isDone;
53     }
54
55     @Override
56     public RpcResult<TransactionStatus> get() throws InterruptedException, ExecutionException {
57         return result;
58     }
59
60     @Override
61     public RpcResult<TransactionStatus> get(long timeout, TimeUnit unit) throws InterruptedException,
62             ExecutionException, TimeoutException {
63         return result;
64     }
65
66     public static class Builder {
67
68         private boolean cancel;
69         private boolean isCancelled;
70         private boolean isDone;
71         private RpcResult<TransactionStatus> result;
72
73         public Builder cancel(boolean cancel) {
74             this.cancel = cancel;
75             return this;
76         }
77
78         public Builder isCancelled(boolean isCancelled) {
79             this.isCancelled = isCancelled;
80             return this;
81         }
82
83         public Builder isDone(boolean isDone) {
84             this.isDone = isDone;
85             return this;
86         }
87
88         public Builder rpcResult(RpcResult<TransactionStatus> result) {
89             this.result = result;
90             return this;
91         }
92
93         public Future<RpcResult<TransactionStatus>> build() {
94             return new DummyFuture(this);
95         }
96     }
97 }